Bazı javascript dosyalarını test etmeyi öğrenmeye çalışıyorum. Webpack ile mocha ve chai kullanarak.Birim Testi Javascript - Nesne bir kurucu değil
Bu benim test/karma.conf.js
var webpack = require('webpack');
module.exports = function (config) {
config.set({
browsers: [ 'PhantomJS' ],
singleRun: true,
frameworks: [ 'mocha' ],
files: [
'tests.webpack.js'
],
preprocessors: {
'tests.webpack.js': [ 'webpack', 'sourcemap' ]
},
reporters: [ 'spec' ],
webpack: {
devtool: 'inline-source-map',
module: {
loaders: [
{ test: /\.js$/, loader: 'babel-loader' }
]
}
},
webpackServer: {
noInfo: true
}
});
};
Ve karma yapılandırmasına kullanmak bu test/test.webpack.js
geçerli:
import chai from 'chai'
global.chai = chai
global.expect = chai.expect
global.should = chai.should()
var context = require.context('../src', true, /spec\.js$/);
context.keys().forEach(context);
benim test sadece src/index.spec.js
çalışıp çalışmadığını test etmek için, çok temel:
describe("A test suite", function() {
beforeEach(function() { });
afterEach(function() { });
it('should fail', function() { expect(true).to.be.true; });
});
Testleri çalıştırmayı denediğimde, Bu hata
./node_modules/karma/bin/karma start test/karma.conf.js
01 04 2016 14:15:08.191:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
01 04 2016 14:15:08.255:INFO [launcher]: Starting browser PhantomJS
01 04 2016 14:15:12.443:INFO [PhantomJS 2.1.1 (Windows 8 0.0.0)]: Connected on socket /#GivXNjnm0g5H9DBXAAAA with id 29314805
PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR
TypeError: Object is not a constructor (evaluating '$export($export.S + $export.F * !__webpack_require__(17), 'Object', { defineProperty: __webpack_require__(13).f })')
at C:/Users/pablo.feldman/Documents/Projects/jpmc-components/test/tests.webpack.js:535 <- webpack:///~/babel-runtime/~/core-js/library/modules/es6.object.define-property.js:3:0
PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 0 of 0 ERROR (0.101 secs/0 secs)
'global.should = chai.should()' olmamalı 'global.should çalıştı
kullanım
arasında = chai.should'? – henry700
@ henry700 Hayır, – tyler
olduğu gibi doğru olması gerekir. Hata iletisi, webpack yapılandırmanızın bir hata verdiğini belirtir. Bunu da gönderebilir misin? – Charminbear