#Just follow this guide and install needed packages https://www.npmjs.com/package/karma-fixture
Created
June 10, 2016 20:49
-
-
Save aw3s0me/882409f5a0c2f0e1d0c332bed0de0d26 to your computer and use it in GitHub Desktop.
Loading fixtures (mocks) in karma-mocha-chai
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var webpack = require('webpack'); | |
| module.exports = function(config) { | |
| config.set({ | |
| browsers: ['PhantomJS'], | |
| singleRun: !!process.env.CI, | |
| frameworks: [ 'mocha', 'fixture' ], | |
| files: [ | |
| './node_modules/phantomjs-polyfill/bind-polyfill.js', | |
| 'tests.webpack.js', | |
| { | |
| pattern: 'fixtures/*', | |
| watched: true, | |
| served: true, | |
| included: true | |
| } | |
| ], | |
| preprocessors: { | |
| 'tests.webpack.js': [ 'webpack', 'sourcemap' ], | |
| //configure Karma to load all html | |
| //and JSON fixture files via those preprocessors: | |
| '**/*.html' : ['html2js'], | |
| '**/*.json' : ['json_fixtures'] | |
| }, | |
| jsonFixturesPreprocessor: { | |
| //setup the karma-json-fixtures-preprocessor plugin | |
| variableName: '__json__' | |
| }, | |
| reporters: [ 'mocha' ], | |
| plugins: [ | |
| require('karma-webpack'), | |
| require('karma-mocha'), | |
| require('karma-mocha-reporter'), | |
| require('karma-phantomjs-launcher'), | |
| require('karma-sourcemap-loader'), | |
| require('karma-fixture'), | |
| require('karma-html2js-preprocessor'), | |
| require('karma-json-fixtures-preprocessor'), | |
| ], | |
| webpack: { | |
| devtool: 'inline-source-map', | |
| module: { | |
| loaders: [ | |
| { test: /\.(jpe?g|png|gif|svg)$/, loader: 'url', query: {limit: 10240} }, | |
| { test: /\.js$/, exclude: /node_modules/, loaders: ['babel']}, | |
| { test: /\.json$/, loader: 'json-loader' }, | |
| { test: /\.less$/, loader: 'style!css!less' }, | |
| { test: /\.scss$/, loader: 'style!css?modules&importLoaders=2&sourceMap&localIdentName=[local]___[hash:base64:5]!autoprefixer?browsers=last 2 version!sass?outputStyle=expanded&sourceMap' } | |
| ] | |
| }, | |
| resolve: { | |
| modulesDirectories: [ | |
| 'src', | |
| 'node_modules' | |
| ], | |
| extensions: ['', '.json', '.js'] | |
| }, | |
| plugins: [ | |
| new webpack.IgnorePlugin(/\.json$/), | |
| new webpack.NoErrorsPlugin(), | |
| new webpack.DefinePlugin({ | |
| __CLIENT__: true, | |
| __SERVER__: false, | |
| __DEVELOPMENT__: true, | |
| __DEVTOOLS__: false // <-------- DISABLE redux-devtools HERE | |
| }) | |
| ] | |
| }, | |
| webpackServer: { | |
| noInfo: true | |
| } | |
| }); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import VowlParser from '../VowlParser'; | |
| import {expect} from 'chai'; | |
| describe('parseVowl', () => { | |
| before(() => { | |
| fixture.setBase('fixtures'); | |
| }); | |
| beforeEach(function(){ | |
| this.result = fixture.load('example.json'); | |
| }); | |
| afterEach(() => { | |
| fixture.cleanup(); | |
| }); | |
| it('gets nodes from vowl file', () => { | |
| let res = fixture.load('example.json'); | |
| //console.log(res); | |
| const parser = new VowlParser(); | |
| const nodes = parser.getNodes(res); | |
| expect(nodes).to.deep.equal({}); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment