InCuca/loopback-jest

View on GitHub
src/matchers/to-have-relationship.js

Summary

Maintainability
A
0 mins
Test Coverage
export default function toHaveRelationship(received, name, model) {
  const { settings } = received.definition;
  const passMsg = () => `expected received model to not have the relationship ${name} with ${model} model`;
  const failMsg = () => `expected received model to have the relationship ${name} with ${model} model`;
  let pass = !this.isNot;
  const expect = (thing) => {
    if (this.isNot) {
      return global.expect(thing).not;
    }
    return global.expect(thing);
  };
  try {
    expect(settings.relations).toMatchObject({
      [name]: { model },
    });
  } catch (err) {
    pass = !pass;
  }
  return { pass, message: pass ? passMsg : failMsg };
}