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

Factory.define is not working! #36

Open
IanChok opened this issue Nov 12, 2021 · 5 comments
Open

Factory.define is not working! #36

IanChok opened this issue Nov 12, 2021 · 5 comments

Comments

@IanChok
Copy link

IanChok commented Nov 12, 2021

if (Meteor.isServer) {
  describe('Workspaces Methods', function () {
    Factory.define('workspace', CollectionWorkSpaces, {
      owner: () => 'ABC',
      participant_ids: () => ['123'],
      invitee_emails: () => []
    });

    beforeEach(function () {
      resetDatabase();
    });

    it('updates invitee email list', function () {
      const document1 = Factory.create('workspace');
      console.log(document1); 
    })
  });
}
//output of document1
{
  _id: '7Qc9PTQpxCesqZS5k',
  owner: '3a6rW9QqnoTpMctCd',
  participant_ids: [],
  invitee_emails: []
}

//expected output:
{
  _id: '7Qc9PTQpxCesqZS5k',
  owner: 'ABC',
  participant_ids: ['123'],
  invitee_emails: []
}

Meteor version 2.5
dburles:factory version 1.1.0

@dburles
Copy link
Collaborator

dburles commented Nov 12, 2021

Hey @IanChok there must be something else at play. Can you try to create a reproduction test in the package tests?

  1. Fork the repo
  2. Write a test case that reproduces the bug
  3. Run meteor test-packages ./ to try it out
  4. Create a PR with a fix (if possible!)

@IanChok
Copy link
Author

IanChok commented Nov 13, 2021

Odd, it's working now... I ignored the error, and just continued developing. After a while I came back and now it seems to be working. I have no idea what I did to cause the issue in the first place, nor what I did to fix it 😅 I guess issue resolved

@IanChok IanChok closed this as completed Nov 13, 2021
@IanChok
Copy link
Author

IanChok commented Nov 16, 2021

Actually the issue came back in a different test file. I'll try to create a repro soon if I get some free time!

@IanChok IanChok reopened this Nov 16, 2021
@IanChok
Copy link
Author

IanChok commented Nov 16, 2021

@dburles Ah ok, I've discovered that to get Factory.define working, it needs to be put inside the before() function of the mocha framework. In the above example, to get it working it should look like this instead

if (Meteor.isServer) {
  describe('Workspaces Methods', function () {
    before(() => {
             Factory.define('workspace', CollectionWorkSpaces, {
                 owner: () => 'ABC',
                 participant_ids: () => ['123'],
                 invitee_emails: () => []
            });
     })
    beforeEach(function () {
      resetDatabase();
    });

    it('updates invitee email list', function () {
      const document1 = Factory.create('workspace');
      console.log(document1); 
    })
  });
}

Then the output is

//output of document1
{
  _id: '7Qc9PTQpxCesqZS5k',
  owner: 'ABC',
  participant_ids: ['123'],
  invitee_emails: []
}

I'm not sure if Factory.define is intended to be put in a before() function or if that's just the case with the mocha framework. In either case, I'd recommend that this is documented somewhere in the Read.me

@dburles
Copy link
Collaborator

dburles commented Nov 16, 2021

Can you recreate the bug in a standalone application and link it here? We still don't know the root cause of the issue.

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

2 participants