Skip to content

Override FactoryBot association with cy.appFactories result #97

@chasedeanda

Description

@chasedeanda

In the FactoryBot docs they give a simple example on overriding associations by passing an existing one into the create command:

FactoryBot.define do
  factory :author do
    name { 'Taylor' }
  end

  factory :post do
    author
  end
end

eunji = build(:author, name: 'Eunji')
post = build(:post, author: eunji)

My attempt to recreate this in Cypress:

cy.appFactories([["build", "author", { name: "Eunji" }]]).then(
  ([author]) => {
    cy.appFactories([["build", "post", { author }]]);
  }
);

The command to build the post fails because author is returned as json and is not actually an instance of Author which throws an Author expected, got {...} which is an instance of Hash error in FactoryBot. Any guidance on using the results from a build command in a new build call?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions