angularjs - Angular, Karma, tsify, woes -
i'm trying set tests, using angular 1.5, tsify, , karma. i'm very, close, i'm running issue haven't quite got right:
i'm following setup described here: https://github.com/cmlenz/tsify-test (this example doesn't include angular)
i error angular-mocks: "cannot set property 'mock' of undefined"
that has either timing thing or scope thing -- either angular-mocks loading soon, or browserify wrapping scope of angular variable, , mocks can't see it. no idea.
here pertinent parts of karma.conf.js file:
frameworks: ['browserify', 'jasmine'], files: [ 'https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js', './node_modules/angular-mocks/angular-mocks.js', './modules/**/*.spec.ts' ], exclude: [], preprocessors: { '**/*.ts': 'browserify' }, browserify: { debug: true, plugin: [ ['tsify'] ] }, this must have way i'm loading mocks -- it's not used angular app, tests, must have it.
any hints?
angular-mocks needs loaded after angular , current karma configuarion, that's not happening - angular not being loaded until it's required in 1 of .ts files upon 1 of .spec.ts files dependent.
one solution add additional file requires both angular , angular-mocks , ensure file precedes .spec.ts files in karma's files configuration.
for example, file named require-angular-mocks.js created:
require('angular'); require('angular-mocks'); and added karma configuration (replacing angular-mocks under node_modules):
files: [ 'https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js', './require-angular-mocks.js', './modules/**/*.spec.ts' ], preprocessors: { '**/*.js': 'browserify', '**/*.ts': 'browserify' }, that should ensure angular , angular-mocks loaded in correct order , loaded before specs. note if it's .js file, you'll need entry in karma's preprocessors configuration.
Comments
Post a Comment