-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow dynamic instance method calls on FactoryBot objects in Cypress (#…
…696) * Init with first ideas about proxies (not working yet) * Improve approach (still doesn't work) * Include temporary FactoryBot dynamic method assignment test * Add example for direct method assignment * Add first working example of dynamic method creation * Refactor first working minimal example * Allow dynamic method access only on .call object This is due to https://stackoverflow.com/q/79016566/9655481 * Implement call to instance methods * Also wrap `.then()` call * Remove custom rails number test method * Improve create() method docstring * Rename method to avoid confusion with "factories" * Add docstrings to transform_hash function & don't use Regex * Add Cypress tests to test array as argument * Allow creation of multiple users of same role e.g. multiple generic users * Fix creation of user in cypress tests This failed due to random hash added to the mail address in the last commit.
- Loading branch information
Showing
6 changed files
with
212 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import FactoryBot from "../../support/factorybot"; | ||
|
||
describe("FactoryBot.create()", () => { | ||
beforeEach(function () { | ||
cy.createUserAndLogin("teacher").as("teacher"); | ||
}); | ||
|
||
it("allows to call create() with array as argument", function () { | ||
cy.createUser("generic").as("tutor1"); | ||
cy.createUser("generic").as("tutor2"); | ||
FactoryBot.create("lecture", { teacher_id: this.teacher.id }).as("lecture"); | ||
|
||
cy.then(() => { | ||
// here we pass in an array as argument to tutor_ids | ||
FactoryBot.create("tutorial", | ||
{ lecture_id: this.lecture.id, tutor_ids: [this.tutor1.id, this.tutor2.id] }, | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("FactoryBot.create().call", () => { | ||
beforeEach(function () { | ||
cy.createUser("teacher").as("teacher"); | ||
cy.createUserAndLogin("generic"); | ||
}); | ||
|
||
it("allows to call instance methods after assigning them to an alias", function () { | ||
FactoryBot.create("lecture", { teacher_id: this.teacher.id }).as("lecture"); | ||
|
||
cy.then(() => { | ||
// via alias in global this namespace | ||
this.lecture.call.long_title().then((res) => { | ||
cy.log(res); | ||
}); | ||
}); | ||
}); | ||
|
||
it("allows to call instance methods directly (without an alias)", function () { | ||
FactoryBot.create("lecture", { teacher_id: this.teacher.id }).then((lecture) => { | ||
// via return value of FactoryBot.create() directly (no alias intermediate) | ||
lecture.call.long_title().then((res) => { | ||
cy.log(res); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters