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
2
votes
1 answer

How to test angular 7 component with ActiveRoute.snapshot.data and Router?

I have a TitleComponent that uses ActivedRoute.snapshot.data and Router to update data from app-routing. This is my app-routing.module export const routes: Routes = [ { path: '', redirectTo: '/home', pathMatch: 'full' }, { path: 'home', …
user9714967
  • 1,534
  • 3
  • 13
  • 21
2
votes
2 answers

Nock not intercepting http requests

I am currently using node-fetch and nock for an express server that sits on top of an angular project. I have the following middleware that is making a call to an api: export const middleware = async(response: any) => { try { const…
Alejandro
  • 623
  • 1
  • 9
  • 22
2
votes
1 answer

Angular 2+ Unit Test - fixture.detectChanges() removes component properties

I have this test. In there i setup some values of my component. These values determine the status of a button. Right before fixture.detectChanges() those values are still set. But after (right at const createButton....) those values are gone and set…
Sebastian
  • 451
  • 6
  • 19
2
votes
1 answer

Unit testing Angular component + ngrx store

Trying to testing my angular component. I've got root state and module state, it looks like: state { auth: { // user data }, messagesModule:{ // here's module state messages:[...] } } Initial messages state is empty…
stue
  • 21
  • 1
  • 2
2
votes
0 answers

Why would my Angular Tests give inconsistent results?

In my angular app, we have a 'LayoutContainer' class that just shows the title of our website and then a navbar with static links. I needed to be able to make the links dynamic based on who the logged in user is -- if they are an admin, I want to be…
Benny
  • 186
  • 1
  • 1
  • 11
2
votes
2 answers

Karma Test Parameter --watch=false don't work

We have an problem to run our Jasmine tests. If we run: ng test --browsers=ChromeHeadless --code-coverage the tests are working. But if we run: ng test --watch=false --browsers=ChromeHeadless --code-coverage it does not work and we get this…
Ivan Demin
  • 101
  • 2
  • 9
2
votes
1 answer

What is considered the correct way to test methods that return http observables?

I have a TypeScript project which I would like to deploy as JS NPM package. This package performs some http requests using rxjs ajax functions. Now I would like to write tests for these methods. At some point I have a method like this…
andreas
  • 7,844
  • 9
  • 51
  • 72
2
votes
1 answer

how to write unit test cases for App_Initializer using Karma/Jasmine in angular 7

I have imported APP_INITIALIZER in my app.module.ts file and calling a initializer function. How to write unit test case for this initializer method using jasmine/karma? Code: initializer.ts import { CookieService } from 'ngx-cookie-service'; import…
2
votes
1 answer

Karma rendering html over test results

Should I exclude the material theme.scss, I get this... However, should I include the theme, I get this... I've searched for about an hour and a half now, there seems to be no way around this. I just want to test my app and use angular material…
DGmip
  • 193
  • 2
  • 9
2
votes
2 answers

How to fix No provider for ChangeDetectorRef! in Karma-Jasmine Testing

StaticInjectorError(DynamicTestModule)[MatTable -> ChangeDetectorRef]: StaticInjectorError(Platform: core)[MatTable -> ChangeDetectorRef]: NullInjectorError: No provider for ChangeDetectorRef! import { async, ComponentFixture, TestBed }…
Gayatri G
  • 31
  • 1
  • 7
2
votes
1 answer

How to include HTML files in karma frontend testing via jasmine

I'm trying to create frontend headless browser testing via karma/jasmine, but it seems as if the HTML files were not loaded, only the JS files. Whenever I include a JS file (among the files: [ ]), it is correctly executed, e.g. console.log is…
gaspar
  • 898
  • 1
  • 13
  • 26
2
votes
1 answer

Angular 7 testing with inheritance and global injector

I'm starting a new project in Angular 7 and have a base component to center some of my global variables and services. As the project can grow quite big, I chose this approach to avoid a massive amount of imports at the beginning of each component…
2
votes
3 answers

ReferenceError: spyOnProperty is not defined

it('should update treatment instruction data in UI', async(() => { const spy = spyOnProperty(appService.treatmentInstruction, 'next', 'get').and.returnValue(treatmentInst); component.updateTemplateInUI(); …
2
votes
1 answer

Unit test ViewChild with mat sort and set content, Jasmine and Karma

I have ViewChild with set content. I would like to know how you can test this piece of code using Unit test. This image is code coverage @ViewChild(MatSort) set content(content: ElementRef) { this.sort = content; Iif (this.sort) { …
2
votes
0 answers

Why does Karma show nothing?

Pretty much the title. I've been experimenting with Karma/Jasmine and this keeps happening. Sometimes there are errors in the console, sometimes not. Sometimes I add a blank line or two and it starts working. Sometimes I have to restart the ng test…
lorless
  • 4,126
  • 8
  • 30
  • 41