Lucid: "Cannot read property 'name' of undefined" calling factory.model().create()

Created on 20 Aug 2018  路  1Comment  路  Source: adonisjs/lucid

Package version

v. 5.0.4

Node.js and npm version

node: 10.3.0
npm: 6.4.0

Sample Code (to reproduce the issue)

A sample test case that make use of the "create" method on the defined "User" model.

test("Cannot have two same username", async ({ client, assert }) => {
  const user = await Factory.model("App/Models/User").create();

  const response = await client
    .post("/signup")
    .send({
      username: user.username,
      email: "[email protected]",
      password: "aPassword",
      password_confirmation: "aPassword"
    })
    .end();

  response.assertStatus(400);
  response.assertJSONSubset({
    status: "fail",
    data: {
      errors: [
        {
          message: "unique validation failed on username",
          field: "username",
          validation: "unique"
        }
      ]
    }
  });
});

Launching adonis test gives back Cannot read property 'name' of undefined. I saw you use a name property inside the factory index file, but I didn't have time to check the code better. Am I doing something wrong?

Most helpful comment

I'm sorry, I wasn't defining any blueprint in the factory.js file!

>All comments

I'm sorry, I wasn't defining any blueprint in the factory.js file!

Was this page helpful?
0 / 5 - 0 ratings