Questions tagged [karma-jasmine]

Karma-Jasmine is an adapter for the Jasmine testing framework, which is shipped with Karma by default.

Karma-Jasmine is an adapter for the Jasmine testing framework.

Installation

This plugin ships with Karma by default, and there isn't any need to install it.

The easiest way is to keep karma-jasmine as a devDependency in your package.json file.

{
  "devDependencies": {
    "karma": "~0.10",
    "karma-jasmine": "~0.1"
  }
}

You can simply do it by:

npm install karma-jasmine --save-dev

Configuration

// karma.conf.js
module.exports = function(config) {
  config.set({
    frameworks: ['jasmine'],

    files: [
      '*.js'
    ]
  });
};
6563 questions
77
votes
3 answers

Angular 6 - NullInjectorError: No provider for HttpClient in unit tests

I am importing and using HttpClient in a service as follows: import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; @Injectable({ providedIn: 'root', }) export class MyService { constructor(private…
Kingamere
  • 9,496
  • 23
  • 71
  • 110
74
votes
5 answers

Test a function that contains a setTimeout()

I have a close function in my component that contains a setTimeout() in order to give time for the animation to complete. public close() { this.animate = "inactive" setTimeout(() => { this.show = false }, 250) } this.show is…
ed-tester
  • 1,596
  • 4
  • 17
  • 24
74
votes
1 answer

What is the difference between createspy and createspyobj

I have used in my code like. return $provide.decorator('aservice', function($delegate) { $delegate.addFn = jasmine.createSpy().andReturn(true); return $delegate; }); In that what createSpy do? can i change the…
user3686652
  • 805
  • 1
  • 6
  • 11
67
votes
14 answers

Testing Angular component with unsubscribe Error during cleanup of component

I'm testing a component which subscribe router params. Every test pass and everything works fine. But if I look in the console, I can see an error: Error during cleanup of component ApplicationViewComponent localConsole.(anonymous function) @…
BlackHoleGalaxy
  • 9,160
  • 17
  • 59
  • 103
64
votes
5 answers

Debug Tests in NG Test

I am using Angular CLI and VSCode but none of my breakpoints in my spec files seem to be getting hit when I run ng test? Do I need to do some config?
72GM
  • 2,926
  • 3
  • 27
  • 33
62
votes
10 answers

Error: No provider for "framework:jasmine"! (Resolving: framework:jasmine)

I have run on my windows console: npm install -g yo grunt-cli bower npm install -g generator-angular yo angular Then I started my project with webstorm and did right click on the karma.conf.js file in the project explorer where I have the menu…
HelloWorld
  • 4,671
  • 12
  • 46
  • 78
60
votes
8 answers

Can't bind to 'matMenuTriggerFor' since it isn't a known property of 'button'

I'm getting following error when I try to test an angular component: Error while running jest tests: Can't bind to 'matMenuTriggerFor' since it isn't a known property of 'button'. Here is my html:
60
votes
14 answers

Some of your tests did a full page reload - error when running Jasmine tests

I'm running into an issue where when I run my tests on Jasmine, I get this error below. The problem is, it seems to happen when I try to execute a certain amount of tests. It doesn't seem to be tied to a particular test, as if I comment out some,…
Siraris
  • 1,088
  • 3
  • 13
  • 21
57
votes
4 answers

ReferenceError: module is not defined - Karma/Jasmine configuration with Angular/Laravel app

I have an existing Angular/Laravel app in which Laravel acts as an API to the angular frontend serving only JSON data. The page that loads the angular app, index.php, is currently served by Laravel. From there, Angular takes over. I'm have a very…
Raphael Rafatpanah
  • 19,082
  • 25
  • 92
  • 158
56
votes
14 answers

Karma/Jasmine times out without running tests

I'm trying to run Karma/Jasmine from Grunt on a project generated with http://newtriks.com/2013/12/31/automating-react-with-yeoman-and-grunt/ Karma launches PhantomJS (or Chrome) and, depending on singleRun, it either times out or just sits there…
edoloughlin
  • 5,821
  • 4
  • 32
  • 61
54
votes
2 answers

Unit test Angular with Jasmine and Karma, Error:Can't bind to 'xxx' since it isn't a known property of 'xxxxxx'.

I have a problem with an unit test in angular 5 with Jasmine and Karma. The error is: "Can't bind to 'fruits' since it isn't a known property of 'my-component2'". The unit test code…
bulbasurmsr
  • 595
  • 1
  • 5
  • 11
54
votes
1 answer

what is the real difference between ng test and ng e2e

I am afraid someone close my question but I couldn't find a satisfying question (maybe because I am very limited in Angular 2+ world and I understood something wrong). As far as I could understand after few Hello World done and few YouTube demo…
Jim C
  • 3,957
  • 25
  • 85
  • 162
52
votes
2 answers

Jasmine tests check if html contains text and return boolean

expect(view.$el.html()).toContain('Admin'); The view does contain the word 'Admin' so I was expecting it to return true. How can I achieve this? expect(view.$el.html()).toContain('Admin'); This returns undefined. How can I make it return…
Spdexter
  • 923
  • 1
  • 7
  • 19
48
votes
4 answers

How to resolve promises in AngularJS, Jasmine 2.0 when there is no $scope to force a digest?

It seems that promises do not resolve in Angular/Jasmine tests unless you force a $scope.$digest(). This is silly IMO but fine, I have that working where applicable (controllers). The situation I'm in now is I have a service which could care less…
Terry
  • 14,099
  • 9
  • 56
  • 84
45
votes
5 answers

How to get better test reports in the console?

I have a fairly simple karma.config.js file basePath = '../'; files = [ JASMINE, JASMINE_ADAPTER, 'js/lib/angular*.js', 'test/lib/angular/angular-mocks.js', 'js/**/*.js', 'test/unit/**/*.js' ]; autoWatch = true; browsers =…
blockloop
  • 5,565
  • 5
  • 30
  • 31