Should I write a unit test for a simple interaction with RxJSHow should I unit test threaded code?Unit Testing C CodeIs Unit Testing worth the effort?What is a reasonable code coverage % for unit tests (and why)?Unit test naming best practicesHow do you unit test private methods?JavaScript unit test tools for TDDWhat is Unit test, Integration Test, Smoke test, Regression Test?Writing unit tests in Python: How do I start?Angular/RxJs When should I unsubscribe from `Subscription`
Is it impolite to ask for halal food when traveling to and in Thailand?
What do you do if you have developments on your paper during the long peer review process?
What is this utensil for?
Would Taiwan and China's dispute be solved if Taiwan gave up being the Republic of China?
How to make interviewee comfortable interviewing in lounge chairs
Has my MacBook been hacked?
Are there non JavaScript ways to hide HTML source code?
Is it possible to encode a message in such a way that can only be read by someone or something capable of seeing into the very near future?
To what extent is it worthwhile to report check fraud / refund scams?
Conditionally execute a command if a specific package is loaded
I feel like most of my characters are the same, what can I do?
A drug that allows people to survive on less food
Safely hang a mirror that does not have hooks
How use custom order in folder on Windows 7 and 10
Performance for simple code that converts a RGB tuple to hex string
How do I improve in sight reading?
Can the U.S. president make military decisions without consulting anyone?
Where Does VDD+0.3V Input Limit Come From on IC chips?
I reverse the source code, you negate the output!
The quicker I go up, the sooner I’ll go down - Riddle
Why is there is no screening for Ovarian Cancer?
Resolving moral conflict
Does a GFCI-protected bath light/fan unit need separate neutrals?
How does IBM's 53-bit quantum computer compare to classical ones for cryptanalytic tasks?
Should I write a unit test for a simple interaction with RxJS
How should I unit test threaded code?Unit Testing C CodeIs Unit Testing worth the effort?What is a reasonable code coverage % for unit tests (and why)?Unit test naming best practicesHow do you unit test private methods?JavaScript unit test tools for TDDWhat is Unit test, Integration Test, Smoke test, Regression Test?Writing unit tests in Python: How do I start?Angular/RxJs When should I unsubscribe from `Subscription`
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Let's say we have a simple class that emits a new event to RxJS subject on window.resize event. Pay no attention that perhaps it's too complicated. The key thing is this class emits some event.
export class ResizeService
private resizeSubject = new Subject();
public onResize(): Observable<Window>
return this.resizeSubject.asObservable();
constructor(private eventManager: EventManager)
this.eventManager.addGlobalEventListener('window', 'resize', (e) =>
this.resizeObject.next(<Window>event.target)
)
private onResize(event: UIEvent)
this.resizeObject.next(<Window>event.target);
The question is, speaking of unit tests for this class, should we check if new event, that we emit to RxJS subject is actually going to be received by the client, that called method onResize
. Something like this:
it('should emit a value', fakeAsync(() =>
let subscriptionWorks = false;
fireWindowResizeEvent(new Event(width: 600; height: 400);
resizeService.onResize().subscribe(() => subscriptionWorks = true);
expect(subscriptionWorks).toBeTruthy();
)
)
And then in case if some developer change onResizeMethod to this, the test is going to fail:
public onResize(): Observable<Window>
return this.resizeSubject.asObservable().skip(10);
angular typescript unit-testing rxjs
add a comment
|
Let's say we have a simple class that emits a new event to RxJS subject on window.resize event. Pay no attention that perhaps it's too complicated. The key thing is this class emits some event.
export class ResizeService
private resizeSubject = new Subject();
public onResize(): Observable<Window>
return this.resizeSubject.asObservable();
constructor(private eventManager: EventManager)
this.eventManager.addGlobalEventListener('window', 'resize', (e) =>
this.resizeObject.next(<Window>event.target)
)
private onResize(event: UIEvent)
this.resizeObject.next(<Window>event.target);
The question is, speaking of unit tests for this class, should we check if new event, that we emit to RxJS subject is actually going to be received by the client, that called method onResize
. Something like this:
it('should emit a value', fakeAsync(() =>
let subscriptionWorks = false;
fireWindowResizeEvent(new Event(width: 600; height: 400);
resizeService.onResize().subscribe(() => subscriptionWorks = true);
expect(subscriptionWorks).toBeTruthy();
)
)
And then in case if some developer change onResizeMethod to this, the test is going to fail:
public onResize(): Observable<Window>
return this.resizeSubject.asObservable().skip(10);
angular typescript unit-testing rxjs
No, Unit tests means you just care about checking your functionality, which is the focus should be to test the event being emitted or not. Your receiving client can have another set of test cases to check for those events if available( may be mock in the client).
– nircraft
Mar 28 at 16:05
@nircraft, and how should I test this, if I can't affect my subject, as it'sprivate
? My suggestion is somewhere from the outside, imitating some client's behavior.
– Ivan Timoshin
Mar 28 at 16:10
add a comment
|
Let's say we have a simple class that emits a new event to RxJS subject on window.resize event. Pay no attention that perhaps it's too complicated. The key thing is this class emits some event.
export class ResizeService
private resizeSubject = new Subject();
public onResize(): Observable<Window>
return this.resizeSubject.asObservable();
constructor(private eventManager: EventManager)
this.eventManager.addGlobalEventListener('window', 'resize', (e) =>
this.resizeObject.next(<Window>event.target)
)
private onResize(event: UIEvent)
this.resizeObject.next(<Window>event.target);
The question is, speaking of unit tests for this class, should we check if new event, that we emit to RxJS subject is actually going to be received by the client, that called method onResize
. Something like this:
it('should emit a value', fakeAsync(() =>
let subscriptionWorks = false;
fireWindowResizeEvent(new Event(width: 600; height: 400);
resizeService.onResize().subscribe(() => subscriptionWorks = true);
expect(subscriptionWorks).toBeTruthy();
)
)
And then in case if some developer change onResizeMethod to this, the test is going to fail:
public onResize(): Observable<Window>
return this.resizeSubject.asObservable().skip(10);
angular typescript unit-testing rxjs
Let's say we have a simple class that emits a new event to RxJS subject on window.resize event. Pay no attention that perhaps it's too complicated. The key thing is this class emits some event.
export class ResizeService
private resizeSubject = new Subject();
public onResize(): Observable<Window>
return this.resizeSubject.asObservable();
constructor(private eventManager: EventManager)
this.eventManager.addGlobalEventListener('window', 'resize', (e) =>
this.resizeObject.next(<Window>event.target)
)
private onResize(event: UIEvent)
this.resizeObject.next(<Window>event.target);
The question is, speaking of unit tests for this class, should we check if new event, that we emit to RxJS subject is actually going to be received by the client, that called method onResize
. Something like this:
it('should emit a value', fakeAsync(() =>
let subscriptionWorks = false;
fireWindowResizeEvent(new Event(width: 600; height: 400);
resizeService.onResize().subscribe(() => subscriptionWorks = true);
expect(subscriptionWorks).toBeTruthy();
)
)
And then in case if some developer change onResizeMethod to this, the test is going to fail:
public onResize(): Observable<Window>
return this.resizeSubject.asObservable().skip(10);
angular typescript unit-testing rxjs
angular typescript unit-testing rxjs
asked Mar 28 at 15:59
Ivan TimoshinIvan Timoshin
2514 silver badges19 bronze badges
2514 silver badges19 bronze badges
No, Unit tests means you just care about checking your functionality, which is the focus should be to test the event being emitted or not. Your receiving client can have another set of test cases to check for those events if available( may be mock in the client).
– nircraft
Mar 28 at 16:05
@nircraft, and how should I test this, if I can't affect my subject, as it'sprivate
? My suggestion is somewhere from the outside, imitating some client's behavior.
– Ivan Timoshin
Mar 28 at 16:10
add a comment
|
No, Unit tests means you just care about checking your functionality, which is the focus should be to test the event being emitted or not. Your receiving client can have another set of test cases to check for those events if available( may be mock in the client).
– nircraft
Mar 28 at 16:05
@nircraft, and how should I test this, if I can't affect my subject, as it'sprivate
? My suggestion is somewhere from the outside, imitating some client's behavior.
– Ivan Timoshin
Mar 28 at 16:10
No, Unit tests means you just care about checking your functionality, which is the focus should be to test the event being emitted or not. Your receiving client can have another set of test cases to check for those events if available( may be mock in the client).
– nircraft
Mar 28 at 16:05
No, Unit tests means you just care about checking your functionality, which is the focus should be to test the event being emitted or not. Your receiving client can have another set of test cases to check for those events if available( may be mock in the client).
– nircraft
Mar 28 at 16:05
@nircraft, and how should I test this, if I can't affect my subject, as it's
private
? My suggestion is somewhere from the outside, imitating some client's behavior.– Ivan Timoshin
Mar 28 at 16:10
@nircraft, and how should I test this, if I can't affect my subject, as it's
private
? My suggestion is somewhere from the outside, imitating some client's behavior.– Ivan Timoshin
Mar 28 at 16:10
add a comment
|
1 Answer
1
active
oldest
votes
What I think you are describing is actually an integration test between your ResizeService and your client. So no you do not. No need to unit test that.
You meant "need NO unit test that", I guess. Anyway it should be tested (maybe not in terms of unit test, but in integration one) and we shouldn't just ignore this code. Is it correct?
– Ivan Timoshin
Mar 29 at 6:43
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55402033%2fshould-i-write-a-unit-test-for-a-simple-interaction-with-rxjs%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
What I think you are describing is actually an integration test between your ResizeService and your client. So no you do not. No need to unit test that.
You meant "need NO unit test that", I guess. Anyway it should be tested (maybe not in terms of unit test, but in integration one) and we shouldn't just ignore this code. Is it correct?
– Ivan Timoshin
Mar 29 at 6:43
add a comment
|
What I think you are describing is actually an integration test between your ResizeService and your client. So no you do not. No need to unit test that.
You meant "need NO unit test that", I guess. Anyway it should be tested (maybe not in terms of unit test, but in integration one) and we shouldn't just ignore this code. Is it correct?
– Ivan Timoshin
Mar 29 at 6:43
add a comment
|
What I think you are describing is actually an integration test between your ResizeService and your client. So no you do not. No need to unit test that.
What I think you are describing is actually an integration test between your ResizeService and your client. So no you do not. No need to unit test that.
edited Mar 29 at 12:03
answered Mar 28 at 16:03
Ethan MelamedEthan Melamed
1525 bronze badges
1525 bronze badges
You meant "need NO unit test that", I guess. Anyway it should be tested (maybe not in terms of unit test, but in integration one) and we shouldn't just ignore this code. Is it correct?
– Ivan Timoshin
Mar 29 at 6:43
add a comment
|
You meant "need NO unit test that", I guess. Anyway it should be tested (maybe not in terms of unit test, but in integration one) and we shouldn't just ignore this code. Is it correct?
– Ivan Timoshin
Mar 29 at 6:43
You meant "need NO unit test that", I guess. Anyway it should be tested (maybe not in terms of unit test, but in integration one) and we shouldn't just ignore this code. Is it correct?
– Ivan Timoshin
Mar 29 at 6:43
You meant "need NO unit test that", I guess. Anyway it should be tested (maybe not in terms of unit test, but in integration one) and we shouldn't just ignore this code. Is it correct?
– Ivan Timoshin
Mar 29 at 6:43
add a comment
|
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55402033%2fshould-i-write-a-unit-test-for-a-simple-interaction-with-rxjs%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
No, Unit tests means you just care about checking your functionality, which is the focus should be to test the event being emitted or not. Your receiving client can have another set of test cases to check for those events if available( may be mock in the client).
– nircraft
Mar 28 at 16:05
@nircraft, and how should I test this, if I can't affect my subject, as it's
private
? My suggestion is somewhere from the outside, imitating some client's behavior.– Ivan Timoshin
Mar 28 at 16:10