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
0 answers

No Provider for Storage in Karma Test

I have tried to get these tests to run many times. I'm just really not sure and can't seem to find why it is wrong. I am using the storage module on my Ionic app and when trying to add it to the unit test I get the below error. I'm pretty lost so…
SmiffyKmc
  • 581
  • 1
  • 10
  • 28
4
votes
0 answers

How to correctly use HttpClientTestingModule in Angular 9 with Jasmine/Karma

We have a generic service to make and receive calls to backend controllers. In Angular 4 all the tests were working, but due to new libraries and changes they no longer work. I am now trying to re-write these using HttpClientTestingModule and…
bilpor
  • 2,357
  • 5
  • 21
  • 55
4
votes
1 answer

NgRx Testing - Check order of dispatched actions

I am mocking my NgRx store when running unit tests and creating a Jasmine spy on the store.dispatch() function. With this, I am of course able to verify that: a. an specific action was dispatched via store.dispatch() and b. the number of times the…
Oisín Foley
  • 488
  • 1
  • 10
  • 22
4
votes
1 answer

Setting karma jasmine DEFAULT_TIMEOUT_INTERVAL globally

In my Angular app, I use Karma and Jasmine to run my unit tests. I'd like to change the default timeout interval for async tests, from the 5 seconds default to, let's say, 10 seconds. I see that you can use jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000…
Francesco Borzi
  • 37,945
  • 31
  • 126
  • 195
4
votes
0 answers

jasmine seems doesn't support mock the clock for setImmediate

Here are my tests: For setTimeout, jasmine.clock() and jasmine.clock().tick(...) works fine. index.ts: import * as mod from './mod'; export function main() { setTimeout(() => { mod.foo(); }, 10); } mod.ts: export function foo()…
slideshowp2
  • 38,463
  • 29
  • 127
  • 255
4
votes
1 answer

how to test dynamic parts in a view (dhtml) with rails cucumber, rspec, capybara?

I want both, testing Ajax Content and normal toggled content through Javascript. My Setup is: - Rails 3.1 - Rspec (Edge) - Cucumber (Edge) - Capybara (Edge) For expample, I want to have a Form, which shows particular fields only, if a certain type…
radosch
  • 609
  • 3
  • 7
4
votes
1 answer

How to fix Type 'AsymmetricMatcher' is not assignable to type '() => void'. in jasmine/jest

I have a object config where I send a function callback to a function. test('should create a ComponentMockwith the needed config', () => { const config: EqListeningPlayerConfig = { // more options myCallback:…
distante
  • 4,507
  • 3
  • 29
  • 63
4
votes
2 answers

Trying to run Angular HttpClient Jasmine test against live REST API: nothing happens

I have a simple "Contacts" REST service written in .Net Core. It works fine. I'm trying to write an Angular 8.3 client to talk to it. The first two things I did were: Create Contact.ts and Note.ts (corresponding to the REST models) Create an…
FoggyDay
  • 10,517
  • 4
  • 24
  • 33
4
votes
1 answer

Test if class is changed with Jasmine and Karma

I am trying to test if a button was clicked by the following way: When the button is clicked some element class is changed from wrapper-container to wrapper-container-expanded(I don't want to check if the function is called when the button is…
MD10
  • 814
  • 6
  • 16
4
votes
1 answer

How do I configure paths to my javascript files in the Jasmine / Maven autogenerated ManualSpecRunner.html?

I think the question says most of it. I have an autogenerated ManualSpecRunner.html file as created by maven / jasmine plug-in and I've got it to put itself into the deployable .war by…
Caroline
  • 1,460
  • 3
  • 14
  • 28
4
votes
1 answer

NullInjectorError: StaticInjectorError(DynamicTestModule)[ErrorHandlerInterceptor -> Router]:

I have already added RouterTestingModule to my import for my unit test. But it is still throwing the following error. The only difference is know is that my routing page is different from the norm. I have attached my codes for reference. What is…
shadow
  • 590
  • 1
  • 8
  • 27
4
votes
1 answer

fakeAsync does not work with debounceTime

I'm trying to write unit test for function in Angular app with debounceTime (rxjs). And use fakeAsync for asynchronous testing. And it looks that in test debounceTime gets resolved immediately even if I don't set tick() or set it with small…
Alex Vovchuk
  • 1,698
  • 3
  • 11
  • 32
4
votes
1 answer

How to correctly call function from unit test

When running a code coverage test it says that the function clearAllValues is not being executed in the test but I am calling this function in my tests below tests it('clearAllValues should be called by click', () => { spyOn(component,…
derrickrozay
  • 940
  • 2
  • 11
  • 31
4
votes
1 answer

test angular if else block and subscribe(response => {} block in jasmine

Hi i am new to jasmine& Karma. Facing issue in writing test case on component method. kindly need your inputs. How to test a Angular component method if else block inside subscribe((res) => { ///block} and ToasterService inside it. i have called…
Madhu
  • 55
  • 1
  • 5
4
votes
1 answer

Jasmine test for ActivatedRoute Angular 7

I am trying to write a simple test for ActivatedRoute. Here's what my test looks like. it("should check if subscribes are called in init", () => { const subRouteSpy = spyOn(activatedRouteStub.paramMap, "subscribe"); component.ngOnInit(); …
Mj1992
  • 3,124
  • 10
  • 54
  • 97