Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: describe is not defined #24

Closed
maciej-gurban opened this issue May 5, 2018 · 9 comments
Closed

ReferenceError: describe is not defined #24

maciej-gurban opened this issue May 5, 2018 · 9 comments

Comments

@maciej-gurban
Copy link

  • babel-plugin-tester 5.0.0:
  • node 8.7.0:
  • npm 5.4.2:

Relevant code or config

const pluginTester = require('babel-plugin-tester');

// normally you would import this from your plugin module
function identifierReversePlugin() {
  return {
    name: 'identifier reverse',
    visitor: {
      Identifier(idPath) {
        idPath.node.name = idPath.node.name.split('').reverse().join('')
      },
    },
  }
}

pluginTester({
  plugin: identifierReversePlugin,
  snapshot: true,
  tests: [
    {code: '"hello";', snapshot: false},
    {
      code: 'var hello = "hi";',
      output: 'var olleh = "hi";',
    },
    `
      function sayHi(person) {
        return 'Hello ' + person + '!'
      }
      console.log(sayHi('Jenny'))
    `,
  ],
})

What you did:
Run the sample code from the docs

What happened:
Throws with:

  return describe(describeBlockTitle, function () {
  ^

ReferenceError: describe is not defined
@kentcdodds
Copy link
Member

What testing framework are you using?

@maciej-gurban
Copy link
Author

maciej-gurban commented May 6, 2018 via email

@blankzust
Copy link

node @kentcdodds

@kentcdodds
Copy link
Member

@blankzust, this requires that you run your tests with a framework that supports global describe and it functions. Frameworks like Jest (recommended), Mocha, or Jasmine.

@blankzust
Copy link

ok,I will retry it and thx @kentcdodds

@Li357
Copy link

Li357 commented Aug 11, 2018

How do I get this to work? I've installed Jest globally (and locally), and I've read that Babel comes bundled with babel-jest which should handle the globals right (though I'm trying to use Babel 7, which may conflict with it). But I still get describe is not defined. Is there something I have to import, or configure with Babel/Jest?

@kentcdodds
Copy link
Member

How are you running it?

@Li357
Copy link

Li357 commented Aug 11, 2018

That's what I'm not clear on. Am I supposed to let Jest search for the tests itself, or am I supposed to directly feed the JavaScript module I execute pluginTester into the Node REPL?

I tried:

node test/index.js
jest

Running jest plain does not find the tests. I don't have any Jest configuration.

@kentcdodds
Copy link
Member

I recommend spending a few minutes in the jest documentation 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants