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

Test td.function() after other td fuction() #202

Closed
juniordesenv-zz opened this issue Mar 10, 2017 · 1 comment
Closed

Test td.function() after other td fuction() #202

juniordesenv-zz opened this issue Mar 10, 2017 · 1 comment

Comments

@juniordesenv-zz
Copy link

juniordesenv-zz commented Mar 10, 2017

My test:

    it('Retorna um Cliente', () => {
      const Clientes = {
        findOne: td.function(),
        populate: td.function()
      };


      td.when(Clientes.findOne({ _id: '58b431fd11b5272360652e45' }).populate('endereco.cidade')).thenResolve(modeloPadrao);

      const clientesController = new ClientesController(Clientes);
      return clientesController
                .getById({ params: { _id: '58b431fd11b5272360652e45' } })
                .then(response => expect(response.data).to.be.eql(modeloPadrao));
    });

My controller:

 getById(req) {
    return this.Clientes.findOne(req.params)
        .populate('endereco.cidade')
            .then(result => defaultResponse(result))
            .catch(error => errorResponse(error.message));
  }

Error: TypeError: Cannot read property 'populate' of undefined

@searls
Copy link
Member

searls commented Mar 15, 2017

You're trying to chain findOne and populate, but the Clientes object you've defined doesn't allow that.

You should:

const Clientes = td.object(['findOne', 'populate'])
td.when(Clientes.findOne({ _id: 'lol' })).thenReturn(Clientes)
td.when(Clientes.populate('endereco.cidade')).thenResolve(modeloPadrao)

@searls searls closed this as completed Mar 15, 2017
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