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

Use factory without starting Mirage server #1063

Open
lanhhv84 opened this issue Oct 18, 2022 · 0 comments
Open

Use factory without starting Mirage server #1063

lanhhv84 opened this issue Oct 18, 2022 · 0 comments

Comments

@lanhhv84
Copy link
Contributor

Firstly, thanks for creating this excellent library. This helps me a lot!

Currently, Miragejs works excellently when it comes to testing React components that interact with external APIs.
My setup follows the doc about Factories.

  • (1) Start Mirage server
  • (2) Create test data
  • (3) Render the target component, set some expectations
  • (4) Shutdown Mirage server

But sometimes, I also need to test stateless components by passing data directly as props. In those cases, I think it could be great if I could use Factories to create test data without steps (1) and (4).

Currently, I can do this:

const Factory = MyFactory.extend(mergedExtensions); // (1)
let factory = new Factory(); // (2)
return factory.build(sequence); // (3) -> sequence is managed by the test case

But there are some small issues:

  • Typescript issues:
    • new Factory() -> There is no constructor
    • factory.build(sequence) -> There is no build function exported
  • Code boilerplate. Ideally, I think we should be able to do this:
    • MyFactory.extend(mergedExtensions).build()
      • To achieve this, I think we can add build to the Factory type, and use/store sequence internally if the external sequence is not provided.

I am happy to create an MR for this suggestion if you don't mind!

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

No branches or pull requests

1 participant