Skip to content

Commit

Permalink
Fix Global Callbacks being called twice
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah Bogart committed Feb 11, 2021
1 parent 58935db commit cb56873
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 1 addition & 2 deletions lib/fixture.ts
Expand Up @@ -117,7 +117,6 @@ export class Fixture<T> extends Definition<T> {
getCallbacks(): Callback<T>[] {
this.compile();

const globalCallbacks = this.fixtureRiveter.getCallbacks();
const parentCallbacks = this.parentFixture().getCallbacks();

const definedCallbacks = [
Expand All @@ -126,7 +125,7 @@ export class Fixture<T> extends Definition<T> {
this.getAdditionalTraits().map((t) => t.getCallbacks()),
].flat(2).filter(Boolean);

return globalCallbacks.concat(parentCallbacks, definedCallbacks);
return parentCallbacks.concat(definedCallbacks);
}

traitByName(name: string): Trait<T> {
Expand Down
2 changes: 1 addition & 1 deletion lib/null-fixture.ts
Expand Up @@ -21,7 +21,7 @@ export class NullFixture<T> extends Definition<T> {
}

getCallbacks(): Callback<T>[] {
return [];
return this.fixtureRiveter.getCallbacks();
}

traitByName(name: string): Trait<T> {
Expand Down
9 changes: 9 additions & 0 deletions test/acceptance/callbacks.ts
Expand Up @@ -175,6 +175,12 @@ describe("global callbacks", function() {
f.after("build", (user) => {
user.name = user.name.toLowerCase();
});

f.fixture("child user", User, (ff) => {
ff.after("build", (user) => {
user.name = `childlike: ${user.name}`;
});
});
});

fr.fixture("company", Company, (f) => {
Expand All @@ -193,5 +199,8 @@ describe("global callbacks", function() {
expect(user.name).to.equal("A___john doe___!!!Z");
const company = await fr.build("company");
expect(company.name).to.equal("ACME SUPPLIERS");

const childUser = await fr.build("child user");
expect(childUser.name).to.equal("childlike: john doe");
});
});

0 comments on commit cb56873

Please sign in to comment.