Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ng-dev] Feature request: AsyncTestingController #9

Closed
ersimont opened this issue Dec 10, 2020 · 0 comments · Fixed by #12
Closed

[ng-dev] Feature request: AsyncTestingController #9

ersimont opened this issue Dec 10, 2020 · 0 comments · Fixed by #12

Comments

@ersimont
Copy link
Member

ersimont commented Dec 10, 2020

Idea: Make a new AsyncTestingController to mimic Angular's HttpTestingController, to enable a consistent DX between testing both kinds of APIs.

The API may end up being used something like:

const clipboardController = new AsyncTestingController(navigator.clipboard, ['readText', 'writeText'], ctx);

clipboardController.expectNone('readText');

navigator.clipboard.readText().then((text) => console.log(text));

const calls = clipboardController.match('readText');
// -or-
const calls = clipboardController.match((call: CallInfo<Navigator['readText']>) => true);

const testCall = clipboardController.expectOne('readText');
// -or-
const testCall = clipboardController.expectOne((call: CallInfo<Navigator['readText']>) => {
  // return boolean
});

console.log(testCall.call.args); // `.call` is the jasmine CallInfo object
testCall.flush('resolve with this, with type safety');
testCall.error('a rejection reason of type any');

clipboardController.verify();
  • Should calling flush() or error() after one of them was already called cause an error? (See what HttpTestingController does)?
  • It would be nice for it to optionally interop with an AngularContext to trigger change detection on flush() and error(). (But first verify that zone.js does that in real life.)
  • Use jasmine spies so that it automatically cleans up after itself after each test
@ersimont ersimont changed the title [ng-dev] Async stubbing framework [ng-dev] Feature request: AsyncTestingController Dec 10, 2020
@ersimont ersimont linked a pull request Dec 19, 2020 that will close this issue
ersimont added a commit that referenced this issue Dec 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant