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;








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);










share|improve this question
























  • 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

















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);










share|improve this question
























  • 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













0












0








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);










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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's private? 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












  • @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
















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












1 Answer
1






active

oldest

votes


















0
















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.






share|improve this answer



























  • 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













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
);



);














draft saved

draft discarded
















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









0
















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.






share|improve this answer



























  • 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















0
















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.






share|improve this answer



























  • 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













0














0










0









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.






share|improve this answer















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.







share|improve this answer














share|improve this answer



share|improve this answer








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

















  • 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




















draft saved

draft discarded















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현