Jasmine Matchers not working on Angular 7 and Karma
See original GitHub issueHi,
I am trying to make the Jasmine Matchers to work with Angular 7 and Karma, but I am getting this error: Uncaught TypeError: expect(...).toBeTrue is not a function
on my spec: expect(result.loginSuccess).toBeTrue();
.
I followed the configuration steps on the readme:
- Installed the packages:
jasmine-expect
,karma-jasmine-matchers
and@types/jasmine-expect
. - Added the jasmine matchers to the Karma config:
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular', 'jasmine-matchers'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma'),
require('karma-jasmine-matchers')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../coverage'),
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
- Added the types to the
tsconfig.spec.json
file:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/spec",
"module": "commonjs",
"types": [
"jasmine",
"node",
"jasmine-expect"
]
},
"files": [
"test.ts",
"polyfills.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
}
But I still get an error. Could you help me?
Thanks, Komyg
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
jasmine matcher functions not loading in angularjs/karma unit ...
I'm testing a function that should pull objects from firebase, I've installed the jasmine-expect with karma-jasmine-matchers plugin.
Read more >Unit Testing in Angular App Using Jasmine and Karma Part-2
In this blog, you will learn the remaining things about unit testing in Angular application and how to write unit tests for different ......
Read more >Component testing scenarios - Angular
The first is a sanity test; it confirms that the stubbed UserService is called and working. The second parameter to the Jasmine matcher...
Read more >Testing Angular with Jasmine and Karma (Part 1) - DigitalOcean
Probably not. The reason we test our code is to verify that it behaves as we expect it to. As a result of...
Read more >Chapter 9. Unit-testing Angular applications
The basics of unit testing with the Jasmine framework; The main artifacts from the ... Running unit tests against web browsers with the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I had to add require at the top of my spec class to get this working.
`import ‘jasmine-expect’; // <----- import here import { SessionLogger } from ‘./session-logger’;
describe(‘SessionLogger’, () => { it(‘should have initial value’, () => { expect(SessionLogger.fetch()).toBeEmptyArray(); }); }); `
Hi Jamie,
I think I got it. I added an import to
jasmine-matcher
in mytests.ts
file and the matchers were recognized.Here is my full file:
Thanks for the help, Felipe