The angular2-testing tag has no usage guidance.
1
vote
1answer
19 views
Write angular2 tests and changing the mock return values - make it DRY?
I'm writing some tests for a service and I'm altering the response from mock functions to test various cases. At the moment, every time I want to change the response of a mock, I need to reset the ...
0
votes
0answers
5 views
Errors when e2e testing angular2 app with protractor
I'm trying to run some simple tests on my Angular2 app using protractor. I run ng serve in one command prompt and ng e2e in another. I get several errors/comments related to a session exception. Here ...
0
votes
0answers
16 views
How to test @ionic/storage?
I need to test my service where I'm using @ionic/storage to get and set data in a method. Do I need to mock the whole storage mechanism or what would be the best practice for that?
1
vote
2answers
41 views
Unit testing Angular 2 authGuard; spy method is not being called
I'm trying to unit test my auth guard service. From this answer I was able to get this far, but now when I run the unit test for this, it says Expected spy navigate to have been called.
How to I get ...
0
votes
0answers
15 views
Is there a FactoryGirl version of Jasmine Karma testing?
In Ruby, you can use FactoryGirl to set factories where you save test objects. Is there such a practice in Jasmine/Karma testing?
Currently having to create a lot of instances of the same objects. I ...
3
votes
2answers
61 views
How to mock NavParams in tests?
This might be an Ionic 2 only question, as I don't see NavParams in the Angular 2 docs, but some concepts might translate so I tagged both.
Given that I call navparams.get('somekey') in order to ...
0
votes
1answer
17 views
'expect' was used when there was no current spec
I am learning Angular 2 testing and I am getting an error that currently doesn't make sense to me.
'expect' was used when there was no current spec,
Test:
import {ExperimentsComponent} from "./...
1
vote
1answer
132 views
How to test Angular2 pipe in nodejs with mocha without karma
I'd like to be able to test an Angular2 pipe purely in nodejs environment without including karma etc.
It is possible to use typescript files as test suites for mocha
https://templecoding.com/blog/...
0
votes
0answers
32 views
Angular2 - Mocking up Angular2-toaster for Jasmine Unit testing
More Generalize the question - How to mock up and external library used in Angular2
In my application i am using Angular2-toaster for popup messages. In order write unit test suite(Jasmine)to one of ...
0
votes
0answers
33 views
Karma testing component with a CRUD service
I am creating a test for a component that calls out to a service with CRUD operators. I am confused on how to create the service in the test. The Angular official docs warn against using the actual ...
4
votes
1answer
140 views
Angular: Testing HTTP with MockBackend, is async() really required?
I'm using MockBackend to test code that depends in @angular/http.
All the examples around the web use an asynchronous test setup, like here:
thoughtram: Testing Services with Http in Angular
describe(...
4
votes
1answer
2k views
Angular 2 Final Release Router Unit Test
How do I unit test routers in Angular version 2.0.0 with karma and jasmine?
Here's what my old unit test looks like in version 2.0.0-beta.14
import {
it,
inject,
injectAsync,
...
3
votes
0answers
71 views
Unexpected value 'DecoratorFactory' imported by the module 'DynamicTestModule' - karma-jasmine
I'm getting error during creating Test component instance.
let comp: TaskviewComponent;
let fixture: ComponentFixture;
let deTaskTitle: DebugElement;
let elSub: HTMLElement;
describe('...
1
vote
1answer
58 views
angular 2 testing w/router
I have a component and when a user logs in it routes to a url called /dashboard I am really struggling figuring out why I am getting the following error.
cannot read property 'args' of undefined
I ...
1
vote
0answers
47 views
Protractor click in ionic collection-view
i've tried to setup e2e testing in our ionic2/angular2 project by clicker. Seems it was working but i faced the problem that click or tap doesn't work with collection-view items:
let product = ...
0
votes
1answer
127 views
Angular 2 unit test parsing error using webpack
I'm getting the follow error when I run Angular 2 unit test using webpack:
FAILED TESTS:
Other Trims Tested
✖ should display other trims articles
PhantomJS 2.1.1 (Linux 0.0.0)
Error: ...
11
votes
2answers
4k views
How to fix beforeEachProviders (deprecated on RC4)
Ive just upgraded Angular2 from RC3 to RC4 ...
import {
expect, it, iit, xit,
describe, ddescribe, xdescribe,
beforeEach, beforeEachProviders, withProviders,
async, inject
} from '@angular/...
0
votes
0answers
58 views
Unhandled Promise rejection: Cannot match any routes
When I run this unit test:
it('can click profile link in template', () => {
const landingPageLinkDe = linkDes[0];
const profileLinkDe = linkDes[1];
const aboutLinkDe = linkDes[2];
...
2
votes
1answer
49 views
Expected [ '/' ] to be [ '/' ] - they look the same
I'm trying to test a router outlet.
I originally had:
expect(landingPageLink).toBe('/', '1st link should go to landing page');
I was getting this error:
Error: Expected [ '/' ] to be '/', '1st ...
0
votes
1answer
55 views
CUSTOM_ELEMENTS_SCHEMA not working
I want to use CUSTOM_ELEMENTS_SCHEMA to get rid of an error in my unit test:
Template parse errors: 'login' is not a known element: [ERROR
->]<login #modal></login>
So I add it to ...
1
vote
1answer
32 views
Is there typescript definition for DOM nativeElement?
I am testing an Angular2 component and want to assert nativeElement's property of the component, but there is no typescript definition for it. My test looks like this:
beforeEach( () => {
...
9
votes
3answers
1k views
How to unit test a component that depends on parameters from ActivatedRoute?
I am unit testing a component that is used to edit an object. The object has an unique id that is used in order to grab the specific object from an array of objects that are hosted in a service. The ...
4
votes
1answer
96 views
How to replace a component used in @viewChildren for a test double?
Suppose I have a component I want to test that uses a very complex component. Furthermore it calls some of its methods using references obtained by @viewChildren. For example
@Component({
...
0
votes
0answers
22 views
Add component stylesheet to Jasmine test in Angular 2
I'm running my unit tests and seeing the actual application page below the results. It'd be nice if it had the styling applied to it, as the images etc go massive and it's not worth looking at.
Here ...
0
votes
1answer
66 views
Can't bind to 'ngModel' since it isn't a known property of 'input'. test .spec.ts
I haev been linked to another ticket. This error ONLY occurs in test and I have imported the FormsModule per linked message. I am using Angular 2.2.1.
ngModel not defined in 'ng test' I have ...
0
votes
1answer
37 views
Unit Test with Page object - tests running before Page html elements defined - Angular 2 Jasmine
I have applied the Angular 2 Page Object from the official docs to my tests to simplify setup.
In the docs and so also in my code it has a function called page.addElements that runs in a promise:
...
1
vote
1answer
44 views
Angular2 Testing: Service returning function instead of object array
I want to write some tests for my service written in Angular 2.1.0:
@Injectable()
export class MyService {
api_base_url = 'http://' + environment.apiHost + ':5000/api/';
constructor(private ...
2
votes
1answer
370 views
How to add providers in angular2 jasmine testing spec since addProvider is deprecated in RC6?
I am trying to write my beforeEach like this so that every it gets the required modules / providers:
beforeEach(() => addProviders([
BaseRequestOptions,
MockBackend,
{
...
1
vote
0answers
61 views
Angular 2 Testing the Router Module
I am attempting to test my Router in Angular 2.2.1 to ensure the proper routes are set up and going to the expected location. I've done Google research and have read and re-read the app.component....
0
votes
1answer
67 views
Angular 2 Final Release Router Navigate Unit Test Error
I am getting
Failed: Uncaught (in promise): Error: Cannot find primary outlet to load 'UserList' error.
This happens when unit testing my login component that redirects to admin/userlist using this....
1
vote
2answers
71 views
How do I Mock an Angular 2 route?
I have the following code...
export class LoginComponent {
userName: string;
password: string;
rememberMe: boolean = false;
constructor( private auth: AuthenticationService,
...
0
votes
0answers
78 views
How to avoid Uncaught Error: Template parse errors: when unit testing Angular 2.2.0, webpack?, 2.1.0-beta.2
I'm using Angular Material 2 inside my components template. When I run basic unit test I get Template parse errors. I've tried to import the Angular Material 2 library into the test directly but this ...
3
votes
1answer
29 views
DebugElement.children has a different order than NativeElement.children
I have an html table and want to get all rows (s). However calling .children on a DebugElement or a NativeElement returns a different ordering.
My table:
<tbody>
<tr>
<td>1&...
0
votes
0answers
67 views
Invalid Anonymous System.register call at node_modules/systemjs/dist/system.src.js:3056
I'm trying to add code coverage to my angular 2 app. I don't care what programs i use for that. I just want it done. I've gone for the most documented one which is karma. I had istanbul running ...
0
votes
0answers
16 views
Angular 2 - Best approach for shared test code
I've got some duplicated code in tests of my Angular2 components. I want to extract this code to some helper class. What is the best approach for test helpers in Angular2? Where those files should be ...
0
votes
0answers
32 views
Angular 2 fixture does not contain styles of component in unit test
I'm having trouble with the following.
This is a unit test for a directive, the directive itself should simply change the height style property for the element it's on. I am using a test component as ...
0
votes
2answers
33 views
Angular2 quickstart: how should I include a new npm package?
I setup the environment by cloning the angular2 quick start repo: https://github.com/angular/quickstart. After I added new package into system.config.js file, the app runs but "npm test" failed. I ...
0
votes
1answer
36 views
Testing: How to lookup component instance for sub-component
I have a component I am testing that has a large number of subcomponents. In my test I would like to get a reference to the objects for some of these subcomponents to I can check their properties to ...
0
votes
1answer
212 views
Angular 2.1 Cannot set base providers because it has already been called(…)
I'm trying to test a basic angular 2 component that Includes a service. When I run my test I'm getting the following errors. The component, service and test are pretty small, they run fine in the ...
0
votes
0answers
19 views
Is there a way to mock module level function in angular2
I am using a custom annotation in angular2 as below
@CustomComponent({
selector: 'app-root',
templateUrl: './app.component.html',
rootCssUrl: 'ife-beagle.css'
})
export class AppComponent {
...
1
vote
1answer
54 views
Angular 2 keeps adding “/testing” to the end of my file imports - systemjs
I've just started to add unit tests to my angular 2 app and I am having a nightmare, every time I have to import something new into my app that I haven't used before, it adds "/testing" to the end of ...
1
vote
1answer
107 views
Cannot read property 'injector' of null jasmine angular 2
I'm getting this error when running a jasmine spec in angular 2:
Cannot read property 'injector' of null jasmine angular 2
stack trace:
TypeError: Cannot read property 'injector' of null
at ...
0
votes
1answer
55 views
Importing the Angular 2 testing classes ComponentFixture & TestBed causing 404 error
I get this error only when I try to run my jasmine tests. I run them with a spec runner html file.
zone.js:1382 GET
http://localhost:3002/node_modules/@angular/core/bundles/core.umd.js/testing
...
0
votes
1answer
136 views
Angular2 - Unit testing Observable error “Cannot read property 'subscribe' of undefined”
I have a service function which is returning Observable and I am consuming that service inside one of my components. I have written a unit test for the component using the technique posted here. ...
0
votes
0answers
46 views
Protractor E2E testing on Angular2: Page not loaded ERR_CONNECTION_REFUSED
I have been stuck for 2 days trying to create E2E tests for our angular2 application.
We used angular-cli to scaffold our whole app: our app is served correctly with ng serve or ng build. Therefore, ...
2
votes
0answers
76 views
angular 2 unit testing with karma and jasmine, how to simulate offline and timeout
Is there a way to utilise testing angular2 app's behaviour in offline, specifically http requests? Some way to mock offline response maybe.
How could one test http request timeouts? I already asked ...
1
vote
1answer
88 views
angular 2 MockBackend test http timeout?
Is there a way to test http timeout behaviour of a service?
I'm using MockBackend even when setting job's timeout to 0 no logging of 'TIMEOUT' present.
export class MyHttpService {
private ...
1
vote
1answer
75 views
mockBackend = getTestBed().get(MockBackend);?
I am learning testing Angular 2 with Karma, and was wondering about some points in code I didn't understand. After the TestBed "mock module" is configured, the following code runs:
mockBackend = ...
1
vote
0answers
141 views
Whats mistakes with this angular2 unit test setup?
my application is running good but unit test doesn't work.
below error throws when i try to npm test
**
help me to resolve my issue
and whats the correct procedure to follow angular2 unit test,
...
1
vote
1answer
89 views
How to get json data from service method call to test case using angular2 unit testing with karma-Jasmine?
I have trying to get json data from when i calling service method. I got a return object but i didn't get json data. Which part i have to change?
"goods.services.ts"
getAllData(): Observable<...