Skip to content

Commit

Permalink
change around the cascade tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brainkim committed Nov 10, 2020
1 parent 8f51643 commit cbf7c55
Showing 1 changed file with 104 additions and 99 deletions.
203 changes: 104 additions & 99 deletions src/__tests__/cascades.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe("parent-child refresh cascades", () => {
try {
renderer.render(<Component />, document.body);
expect(document.body.innerHTML).toEqual("<div>Hello</div>");
expect(mock).toHaveBeenCalledTimes(1);
expect(mock).toHaveBeenCalled();
} finally {
mock.mockRestore();
}
Expand All @@ -34,7 +34,7 @@ describe("parent-child refresh cascades", () => {
try {
await renderer.render(<Component />, document.body);
expect(document.body.innerHTML).toEqual("<div>Hello</div>");
expect(mock).toHaveBeenCalledTimes(1);
expect(mock).toHaveBeenCalled();
} finally {
mock.mockRestore();
}
Expand All @@ -52,7 +52,7 @@ describe("parent-child refresh cascades", () => {
try {
renderer.render(<Component />, document.body);
expect(document.body.innerHTML).toEqual("<div>Hello</div>");
expect(mock).toHaveBeenCalledTimes(1);
expect(mock).toHaveBeenCalled();
} finally {
mock.mockRestore();
}
Expand All @@ -73,126 +73,131 @@ describe("parent-child refresh cascades", () => {
expect(document.body.innerHTML).toEqual("<span>Hello</span>");
await new Promise((resolve) => setTimeout(resolve, 0));
expect(document.body.innerHTML).toEqual("<span>Hello</span>");
expect(mock).toHaveBeenCalledTimes(1);
expect(mock).toHaveBeenCalled();
} finally {
mock.mockRestore();
}
});

test("sync function parent and sync function child", () => {
return new Promise((done) => {
function Child(this: Context) {
this.dispatchEvent(new Event("test", {bubbles: true}));
return <span>child</span>;
}
function Child(this: Context) {
this.dispatchEvent(new Event("test", {bubbles: true}));
return <span>child</span>;
}

function Parent(this: Context) {
this.addEventListener("test", () => {
this.refresh();
});

return (
<div>
<Child />
</div>
);
}

const mock = jest.spyOn(console, "error").mockImplementation();
try {
renderer.render(<Parent />, document.body);
expect(document.body.innerHTML).toEqual("<div><span>child</span></div>");
} finally {
mock.mockRestore();
}
});

function Parent(this: Context) {
this.addEventListener("test", () => {
try {
this.refresh();
done();
} catch (err) {
done(err);
}
});

return (
test("sync generator parent and sync function child", () => {
function Child(this: Context) {
this.dispatchEvent(new Event("test", {bubbles: true}));
return <span>child</span>;
}

function* Parent(this: Context) {
this.addEventListener("test", () => {
this.refresh();
});

while (true) {
yield (
<div>
<Child />
</div>
);
}
}

const mock = jest.spyOn(console, "error").mockImplementation();
try {
renderer.render(<Parent />, document.body);
expect(document.body.innerHTML).toEqual(
"<div><span>child</span></div>",
);
expect(mock).toHaveBeenCalledTimes(1);
} finally {
mock.mockRestore();
}
});
const mock = jest.spyOn(console, "error").mockImplementation();
try {
renderer.render(<Parent />, document.body);
expect(document.body.innerHTML).toEqual("<div><span>child</span></div>");
expect(mock).toHaveBeenCalled();
} finally {
mock.mockRestore();
}
});

test("sync generator parent and sync function child", () => {
return new Promise((done) => {
function Child(this: Context) {
this.dispatchEvent(new Event("test", {bubbles: true}));
return <span>child</span>;
test("sync generator parent and sync generator child", () => {
function* Child(this: Context) {
this.dispatchEvent(new Event("test", {bubbles: true}));
while (true) {
yield <span>child</span>;
}
}

function* Parent(this: Context) {
this.addEventListener("test", () => {
try {
this.refresh();
done();
} catch (err) {
done(err);
}
});

while (true) {
yield (
<div>
<Child />
</div>
);
}
}
function* Parent(this: Context) {
this.addEventListener("test", () => {
this.refresh();
});

const mock = jest.spyOn(console, "error").mockImplementation();
try {
renderer.render(<Parent />, document.body);
expect(document.body.innerHTML).toEqual(
"<div><span>child</span></div>",
while (true) {
yield (
<div>
<Child />
</div>
);
expect(mock).toHaveBeenCalledTimes(1);
} finally {
mock.mockRestore();
}
});
}

const mock = jest.spyOn(console, "error").mockImplementation();
try {
renderer.render(<Parent />, document.body);
expect(document.body.innerHTML).toEqual("<div><span>child</span></div>");
expect(mock).toHaveBeenCalled();
} finally {
mock.mockRestore();
}
});

test("sync generator parent and sync generator child", () => {
return new Promise((done) => {
function* Child(this: Context) {
while (true) {
this.dispatchEvent(new Event("test", {bubbles: true}));
yield <span>child</span>;
}
}
test("dispatchEvent in initial schedule callback", () => {
function* Child(this: Context) {
this.schedule(() => {
this.dispatchEvent(new Event("test", {bubbles: true}));
});

function* Parent(this: Context) {
this.addEventListener("test", () => {
try {
this.refresh();
done();
} catch (err) {
done(err);
}
});

while (true) {
yield (
<div>
<Child />
</div>
);
}
while (true) {
yield <span>child</span>;
}
}

const mock = jest.spyOn(console, "error").mockImplementation();
try {
renderer.render(<Parent />, document.body);
expect(document.body.innerHTML).toEqual(
"<div><span>child</span></div>",
);
expect(mock).toHaveBeenCalledTimes(1);
} finally {
mock.mockRestore();
}
});
function Parent(this: Context) {
this.addEventListener("test", () => {
this.refresh();
});

return (
<div>
<Child />
</div>
);
}

const mock = jest.spyOn(console, "error").mockImplementation();
try {
renderer.render(<Parent />, document.body);
expect(document.body.innerHTML).toEqual("<div><span>child</span></div>");
expect(mock).toHaveBeenCalled();
} finally {
mock.mockRestore();
}
});
});

0 comments on commit cbf7c55

Please sign in to comment.