Closed davidshen84 closed 5 years ago
You'll need to give me an example of precisely where you are calling create
. If you are doing it in the app component and are using that in unit tests, you will be responsible for ensuring the spy is torn down.
Complete souce code of app.component.ts
.
import {Component} from '@angular/core';
import {create} from 'rxjs-spy';
create();
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'ng-timeout';
}
I thought calling create
at the top is the only option...honestly, I am new to this library. If there's a better place to put create
, please let me know.
I would suggest putting it in main.ts
, which is a module that won't - AFAICT - be imported into any unit tests.
If you choose to place it somewhere else, be aware that create
returns a spy instance and you can call teardown
on it when (and where) you're done with it:
const spy = create();
// ...
spy.teardown();
So the conclusion is that create
should not be invoked during unit test. Thanks!
There's no reason why it cannot be invoked in a unit test - this project creates and tears down spies in its own unit tests - but you need to be aware of what you are doing regarding creating and tearing down spies. And you'd need a good reason for doing it - I don't know why you'd need a spy in a unit test.
No, I don't need a spy in my unit test. The spy got created by the application code, and I did not take care of it.
On Sun, Nov 18, 2018 at 8:31 PM Nicholas Jamieson notifications@github.com wrote:
There's no reason why it cannot be invoked in a unit test - this project creates and tears down spies in its own unit tests - but you need to be aware of what you are doing regarding creating and tearing down spies. And you'd need a good reason for doing it - I don't know why you'd need a spy in a unit test.
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/cartant/rxjs-spy/issues/39#issuecomment-439689411, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEAzRp7uctqAekkJ3k4_zToHurvHaUOks5uwVMwgaJpZM4Ynxjz .
Environment
I can also reproduce this issue on a Linux environment.
Reproduce Steps
create()
in the generated app.component.ts.ng test
.Expected
All tests are run and pass.
Actual
One test failed with timeout error.
Analysis
I discovered this issue while working on my own project. It seems it will cause one unit test case to fail and it alway the same one. But interestingly, if I change the unit test code order, a different one will fail. Also, if I ran only one test case, this issue will not occur.
I know it does not make sense to use this library in unit tests. But it would be better if it does not interfere with unit tests.