5

I am looking at this specific line of code to understand what it is or to find some documentation about it.

https://github.com/adonisjs/adonis-rally/blob/c7378d2c3984bffba1049f50e771318ea447107c/app/Model/Channel.js

const Lucid = use('Lucid')

I am trying to write a test in adonisjs using mocha and it gives me the following error "ReferenceError: use is not defined"

shed_fortest
  • 61
  • 1
  • 3
  • This is not a standard part of Javascript or node.js. In that particular code, it looks like something similar to `require()` that would be in some library which you do not appear to have available. – jfriend00 Dec 21 '16 at 17:23
  • 5
    There is no `use` keyword. That is a function call - some library defines it. You don't seem to have that library loaded. – VLAZ Dec 21 '16 at 17:23
  • Look in the [package.json](https://github.com/adonisjs/adonis-rally/blob/develop/package.json) to see the installed packages – Andrew Li Dec 21 '16 at 17:24
  • I copied the package json from that project i linked to my project and I still cannot run a test. My model looks exactly the same as the model linked. – shed_fortest Dec 21 '16 at 17:36

2 Answers2

7

The use() function is provided by adonis.js.

use(namespace/alias)

Fetch a binding using it’s namespace or alias.

The adonis-lucid package has an example of how to create a model that looks identical to the code that you've linked in your question. Creating a model docs

peteb
  • 15,387
  • 7
  • 44
  • 55
  • thanks for your answer. it was very hard finding documentation and vue.js seems to explain a bunch. As for why my test was throwing an error i copied the test.js from the linked repo and it seems to have resolved my issue. my guess is it has to do with starting the server? – shed_fortest Dec 21 '16 at 17:56
2

To complete the answer. use() function is provided by the IoC Container of AdonisJs (adonis-fold).

This function will try to resolve a binding or a namespace defined in your Adonis configuration file and will then fallback to the default require() function to import a package if it didn't find anything.

Romain Lanz
  • 700
  • 4
  • 13