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

feat: add extend params feature #29

Merged
merged 1 commit into from
Dec 10, 2023

Conversation

thiagomini
Copy link
Owner

Adds the extendParams() method to factories so we can easily create new factories that use specific transient parameter values. Look at the test example below:

    it('extends the factory and pass custom parameters', async () => {
      // Arrange
      type UserTransientParams = {
        prefix: 'Mr.' | 'Mrs.';
      };
      const userFactoryWithTransientParams = FactoryGirl.define<
        User,
        User,
        UserTransientParams
      >(plainObject<User>(), ({ transientParams }) => ({
        ...buildUserAttributes(),
        name: `${transientParams?.prefix} ${buildUserAttributes().name}`,
      }));

      const mrUserFactory = userFactoryWithTransientParams.extendParams({
        prefix: 'Mr.',
      });

      // Act
      const mrUser = await mrUserFactory.build();

      // Assert
      expect(mrUser).toEqual({
        ...buildUserAttributes(),
        name: 'Mr. John Doe',
      });
    });

@thiagomini thiagomini added enhancement New feature or request feature labels Dec 10, 2023
@thiagomini thiagomini self-assigned this Dec 10, 2023
@thiagomini thiagomini merged commit 98aecb2 into main Dec 10, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant