mocha - Getting chai to play nice with requirejs -
I am trying to install Karma / Mocha / Chai in my backbone project, which is more than just using JS And does not have much luck. / P>
First of all, this is my setup:
- app / - js / - bower_components / - node_modules / - test / - test-main.js - karma.conf. The relevant bit of js / / Karma.conf.js framework: ['Mocha', 'need', 'tea'], files: ['test / test-main.js', {pattern:' bower_components / requirejs-text / Text included in JS: False}, {Pattern: 'power_combnt / jquery / dist / jquery.js', includes: wrong}, {Pattern: 'bower_components / underscore / underscore.js', includes: wrong}, {Pattern: Bower_components / backbone / backbone.js ', includes: wrong}, {pattern:' app / js / ** / *. JS ', included: incorrect}, {Pattern:' test / ** / * Spec.js ', included: falz}], excluded: [' app / js / expected config.js ',' app / js / main .Jes '], Preprocessor: {' ** / *. Html ': []}, // test-Main.js var allTestFiles = []; Var TEST_REGEXP = /(spec|test)\.js$\i; Var Pathtoolold = Function (Path) {Return Path. Place (/ ^ \ base / //, ''). Replace (/ \ .js $ /, ''); } Object.Keys (window.__Karma___files) .for eACH (function (file) {if (TESTEEXT.Text (file)} {all test fields. Push (pathemomo module (file))}}); Need.config ({baseUrl: '/ base / app / js', path: {text:' ../../bower_components/requirejs-text/text ', jquery:' ../../bower_components/jquery/ Dist / jquery ', underscore:' ../../bower_components/underscore/underscore ', backbone:' ../../bower_components/backbone/backbone ', test:' ../../test ',} , Dip: all testfile, callback: window .__ karma __. Start;}); Error: Unknown Defined () Module: Function (Module) {/ ->
When I run an action, I get:
- text. The complete contents of js -
I tried changing the order of "frameworks" to change the framework: ['Mocha', 'Tea', 'Requirements'] , Which went away unmatched error, but found:
Type error: 'undefined' is not an object (evaluation 'window.chai.should')
< / Blockquote> This is one and needjs chai < / Em> before it is recommended.
Do anyone need to work? Thank you.
Sorry for wasting a question on Welp, SO I started from scratch and my above configuration ("{Pattern: 'app / js / ** / * .html is separated from the requirement to include, contains: wrong}") worked fine.
Upgrade, here the updated configuration:
- app / - js / - bower_components / - node_modules / - test / - test-main.js - karma.conf .js // ---- Related Bits Karma.conf.js ---- // "requirejs" should be preceded by "Chai" or Chai will not load properly. // SidNot: Karma loads the loaded framework backwards frameworks: ['Mocha', 'Rargez', 'Tea'], // Contrary to some StackHowforflow and Gitob Issue reactions, it has been suggested that, files The sequence of things does not matter at all. Files: ['test / test-main.js', // app files {pattern:' app / js / ** / *. Html ', included: incorrect}, {pattern:' app / js / ** / * .js', include: wrong}, // test {pattern: 'test / ** / * spec.js', Includes: Incorrect}, // Library {Pattern: 'bower_components / jquery / dist / jquery.js', contains: wrong, looking: wrong}, {pattern: 'bower_components / underscore / underscore.js', included Is: false, looking: wrong}, {pattern: 'bower_components / backbone / backbone.js', includes: wrong, looking: false}, {pattern: 'bower_components / requirejs-text / text.js' , Include: false, looking: wrong},], exclude: ['App / JS / expected config.j.a. S ',' ap / js / men.js'], preprocessor: {}, // ---- test-main.js ---- var allTestFiles = []; (For windows .__ karma __ files) {if (window .__ karma __. files.hasOwnProperty (file)) {if (/Spec\.js$/.test(file)} {allTestFiles.push ( File); }}} Require.config ({baseUrl: '/ base / app / js', path: {jquery:' ../../bower_components/jquery/dist/jquery ', underscore:' ../../bower_components / Underscore / underscore ', backbone:' ../../bower_components/backbone/backbone ', text:' ../../bower_components/requirejs-text/text ',}, deps: allTestFiles, callback: window. __karma __. Start;});
Comments
Post a Comment