How to include jasmine?
See original GitHub issueI am using jasmine.createSpyObj() in my tests/examples. But this results in an error in UI-Jar.
__ui-jar-temp-module-689e6bd400733cf8e738d027a2ab7e31.js:19 Uncaught ReferenceError: jasmine is not defined
What do I need to change to make jasmine available?
Here is an example to reproduce the issue:
test.service.ts
import { Injectable } from '@angular/core';
import { Observable, of } from "rxjs";
@Injectable({
providedIn: 'root'
})
export class TestService {
constructor(
) {
}
getSomething(): Observable<any> {
return of('something');
}
}
test.component.ts
import { Component, OnInit } from '@angular/core';
import { TestService } from "./test.service";
/**
* @group Test
* @component TestWithJasmine
*/
@Component({
selector: 'jui-jar-test',
template: `template`
})
export class TestComponent implements OnInit {
constructor(
private testService: TestService
) {
}
ngOnInit(
) {
this.testService.getSomething();
}
}
test.component.spec.ts
import { async, TestBed } from "@angular/core/testing";
import { of } from "rxjs";
import { TestComponent } from "./test.component";
import { TestService } from "./test.service";
describe('TestComponent', () => {
let serviceSpy: jasmine.SpyObj<TestService>;
beforeEach(async(() => {
/**
* @uijar TestComponent
*/
TestBed.configureTestingModule({
declarations: [TestComponent],
providers: [
TestComponent,
{
provide: TestService,
useValue: jasmine.createSpyObj('TestService', ['getSomething'])
}
]
})
.compileComponents();
serviceSpy = TestBed.get(TestService);
serviceSpy.getSomething.and.callFake(
() => {
return of('success');
}
);
}));
/**
* @uijarexample Trigger jasmine error
*/
it(
'should show test component',
() => {
const fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();
}
);
});
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Getting Started - Jasmine Documentation
Jasmine for Node.js. Add Jasmine to your package.json npm install --save-dev jasmine. Initialize Jasmine in your project npx jasmine init.
Read more >An Introduction to Jasmine Unit Testing - freeCodeCamp
Jasmine is the most popular JS library for unit testing web apps. In this tutorial, designed for beginners, we'll present you with a...
Read more >Jasmine Framework Tutorial: Unit Testing with Example
To run the test, you need to execute the jasmine command. This will find all files which have the 'spec' word attached to...
Read more >Jasmine unit testing tutorial with examples - HowToDoInJava
Jasmine is one of the popular JavaScript unit testing frameworks which is capable of testing synchronous and asynchronous JavaScript code.
Read more >Jasmine cheatsheet - Devhints
Note: This cheatsheet may be a little outdated. Also see the Jest cheatsheet. Jest uses Jasmine, and therefore has similar API. Expectations. expect( ......
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 FreeTop 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
Top GitHub Comments
I got a step further by creating my own jasmine boot script and including it into
polyfill.ts
:Now
jasmine.createSpyObj()
is available and works. I modified the test component to use the mock.test.component.ts
Using the HTTPClient example from the readme I modified the spec file to provide it. It works fine in Karma, but the mock method is never initialized in UI-Jar.
``ERROR TypeError: Cannot read property ‘subscribe’ of undefined`
test.component.spec.ts
Any suggestion how the spec file should look for UI-Jar?
I have added the below mentioned code with my polyfills but running UI-Jar test is still giving exception.