Questions tagged [jasmine]

Jasmine is a behavior-driven development (BDD) framework for testing JavaScript code. Jasmine has no external dependencies and does not require a DOM.

Jasmine is a stand-alone behavior-driven development (BDD) framework used for unit testing JavaScript code.

Jasmine tests are broken up into describe and it statements. describe is used to denote the start of a test suite and it is used to denote the start of a particular test. expect statements are then used to outline the conditions under which a test should pass.

beforeEach and afterEach are some other frequently used blocks. beforeEach is used to run some code before each test. Something like loading a module. Similarly afterEach is used to run some code after each test. Running some cleanup code for instance.

Jasmine DOM Testing

If you want to write unit tests for code that does a lot of DOM interactions using jQuery, consider using jasmine-jquery. Jasmine-jQuery offers interacting with dummy HTML through HTML fixtures.

Resources

12446 questions
4
votes
1 answer

Jasmine Testing - How to test for a class being applied?

I am currently creating my first JS project and am trying Jasmine unit testing for the first time. In my code, I want to test the function in one of my classes which applies a css class to a button element. However I am having difficulty getting…
SamJP
  • 43
  • 4
4
votes
1 answer

How to accept permission for getUserMedia() in jasmine testing?

I'm writing an AudioRecorder class whose init() accesses Navigator.mediaDevices.getUserMedia({audio: true}). Is there a way to accept the user permission request in the DOM from Jasmine? Source: export default class AudioRecorder { async init()…
Minh Lam
  • 51
  • 4
4
votes
1 answer

How to unit test an Angular @Input's setters and getters

How could I get the unit test coverage for a component @Input that is an object stringify using a setter and getter. The code is working fine, the thing is I can't get fully unit test coverage. The selector looks like:
4
votes
1 answer

Unit Test for function with mat paginator method firstPage()

I have a function I am trying to test. I am using the matPaginator.firstPage() method inside of it. However any test I write for this function I can an error of "Cannot read property 'firstPage' of undefined" I cannot find anything on how to mock…
Brian Stanley
  • 1,503
  • 5
  • 16
  • 38
4
votes
1 answer

Test adding class to the in angular 7

I have this root AppComponent that listenens for a change on a service, and then adds or removes a CSS class on the document.body import { Component, OnInit, Renderer2 } from '@angular/core'; import { SideMenuService } from…
CBarr
  • 21,475
  • 18
  • 85
  • 119
4
votes
0 answers

Setting specFilter directly on Env is deprecated

These are my setup after I upgraded to Agnular 7 and TypeScript 3.2. I'm running karma jasmine tests using these packages. "jasmine-core": "^3.3.0", "jasmine-spec-reporter": "^4.2.1", "karma": "^4.0.1", "karma-chrome-launcher":…
user1019042
  • 2,276
  • 8
  • 36
  • 75
4
votes
1 answer

Expected one matching request, found 2 requests. How do I test for 2 requests

I am working on an Angular application and I am using Jasmine to test the application. What I want is to test for two similar HTTP requests in one method such as, ngOnInit() . I have an HTTP request that is called twice in ngOnInit() method…
Saurabh Gupta
  • 125
  • 2
  • 12
4
votes
1 answer

Typescript unit test private and protected methods

I want to be able to test private Typescript methods. Please skip your lecture of why this is a bad idea. I've heard it. Here is a demo code: class MyClass { age: number private ageAsString(): string { return '15' } } Here are…
Esqarrouth
  • 35,175
  • 17
  • 147
  • 154
4
votes
1 answer

Is it possible to modify or mock the Inversify container used by a Typescript class in a Jasmine unit test?

I have a Typescript class that uses InversifyJS and Inversify Inject Decorators to inject a service into a private property. Functionally this is fine but I'm having issues figuring out how to unit test it. I've created a simplified version of my…
Gavin Sutherland
  • 1,496
  • 1
  • 20
  • 34
4
votes
1 answer

Jasmine HTTP tests not getting coverage on RXJS pipeline

Problem Hey everyone, I'm adding some Karma-Jasmine unit-testing to my Angular 2 project and I cannot for the life of me get the coverage to hit the RXJS operators in my service methods. The tests are using the HttpClientTestingModule and…
Robert Lee
  • 125
  • 1
  • 7
4
votes
0 answers

How to spy on a service in Angular E2E test with Protractor

I'm having troubles when trying to spy on a service's method so that I can return a faked value in an Angular E2E test with Protractor. This is the component (loaded when the route '/date' is hit): @Component({ selector: 'app-date', template: ` …
baumgarb
  • 1,416
  • 1
  • 17
  • 23
4
votes
1 answer

How to do jasmine unit test case for angular 6 bootstrap 4 modal

html

Modal content inside this ng-template #content

Button to open model In ts file import { NgbModal, ModalDismissReasons }…
Reshma
  • 472
  • 2
  • 9
  • 20
4
votes
1 answer

Use Jasmine custom matcher with Angular CLI project

I have a simple need: to use my own custom matchers in Jasmine unit tests within an Angular CLI project (Angular v6). A couple constraints: I do not want to modify anything under node_modules; this project has to be able to go through my build…
Michael Sorens
  • 32,325
  • 20
  • 111
  • 165
4
votes
1 answer

What is the correct way of testing chained catchError functions

I'm trying to write a jasmine test for an @Effect that has chained rxjs catchError operators, but am struggling to test any observables beyond the first catchError. here's the effect: @Effect() submitEndsheets$ = this.actions$.pipe( …
mpaarating
  • 53
  • 1
  • 7
4
votes
1 answer

How can I get jasmine-ts to execute my specs with a specific seed?

I am running unit tests using jasmine-ts version 0.3.0. The previous version worked fine, but the moment I upgraded, I'd get the output: No specs found I found a github issue (and this one) where someone commented: All arguments passed to…
pushkin
  • 7,514
  • 14
  • 41
  • 74
1 2 3
99
100