Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

javascript - ReferenceError: Can't find variable: require at

I have a question about using jasmine with Grunt. I keep getting an error,

ReferenceError: Can't find variable: require at

whenever I run my jasmine tests. Here is my jasmine entry for my Gruntfile.js :

jasmine: {
      js: {
        src: jsFiles,
        options: {
          specs: 'tests/*_spec.js',
          helpers: 'tests/helpers/*',
          vendor: 'vendor/*'
        }
      }
    },

I can run a dummy test without a require just fine, but when I include a require in a test, like so, I get the require error.

var testD = require('../src/events_to_actions');

describe("events_to_actions", function() {
  it("is dummy test", function() {
    expect(true).toEqual(true);
  });
});
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I had the same problem. Just install this node package and add this line to your Gruntfile and require should start working again.

https://github.com/cloudchen/grunt-template-jasmine-requirejs

jasmine: {
      js: {
        src: jsFiles,
        options: {
          specs: 'tests/*_spec.js',
          helpers: 'tests/helpers/*',
          vendor: 'vendor/*',
          template: require('grunt-template-jasmine-requirejs')
        }
      }
    },

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...