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

A few more examples, please. #3

Open
rconstantine opened this issue Aug 11, 2021 · 2 comments
Open

A few more examples, please. #3

rconstantine opened this issue Aug 11, 2021 · 2 comments

Comments

@rconstantine
Copy link

Just found this module and I think it may do what I'm looking for.

It looks like the examples are not Jest-specific although this module is for Jest. In particular, I am accustomed to the pattern of a describe block, with a nested set of describe blocks inside, with one or more test calls. A non-sequelize example is this:

describe('Normalize PORT', () => {
    describe('Named PIPE', () => {
        test('should return the named pipe', () => {
            expect(normalizePort('Foo')).toBe('Foo');
        });
    });

    describe('Number PORT', () => {
        test('should return the port number', () => {
            expect(normalizePort(8090)).toBe(8090);
        });
    });
});

I see the example has a describe block but no test calls inside. Instead, this appears to be the first test:

checkModelName(User)('User')

How should checkModelName be used to match the Jest pattern of use?

@rconstantine
Copy link
Author

Well, I found that checkModelName can't be put inside a test block. So perhaps the only thing I'm wondering now is if the checkModelName call can be named, like tests can be.

@rconstantine
Copy link
Author

I got a couple of things working. The first two tests below work. The third does not, but I think it should. Can you point me in the right direction with the third one? I have many tables with belongsToMany connections using through and foreignKey, so I need to figure this out. When I try the below, a gigantic Object is indicated as received. Any help would be appreciated.

Note: you didn't change the example on the Read.me and I think it is using chai/sinon syntax which doesn't work for Jest.

describe('Check table associations', () => {
    test('AbilityGroups.hasMany(Abilities)', () => {
      const spy = jest.spyOn(AbilityGroups, 'hasMany');
      AbilityGroups.hasMany(Abilities);
      expect(spy).toHaveBeenCalledWith(Abilities);
      spy.mockRestore();
    })
    test('Abilities.belongsTo(AbilityGroups)', () => {
      const spy = jest.spyOn(Abilities, 'belongsTo');
      Abilities.belongsTo(AbilityGroups);
      expect(spy).toHaveBeenCalledWith(AbilityGroups);
      spy.mockRestore();
    });
    test('Users.belongsToMany(Roles)', () => {
      const spy = jest.spyOn(Users, 'belongsToMany');
      Users.belongsToMany(Roles, {through: 'users_roles', foreignKey: 'user_id'});
      expect(spy).toHaveBeenCalledWith(Roles, {through: 'users_roles', foreignKey: 'user_id'});
      spy.mockRestore();
    });
  });

Here is the example from the Read.me:

it("defined a belongsToMany association with Category through CategoriesCompanies as 'categories'", () => {
  expect(Company.belongsToMany).to.have.been.calledWith(Category, {
    through: CategoriesCompanies,
    as: 'categories'
  })
})

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