@testing-library/react-render-stream
Version:
## What is this library?
93 lines (87 loc) • 2.26 kB
JavaScript
// src/expect/index.ts
import { expect } from "expect";
// src/expect/renderStreamMatchers.ts
import {
WaitForRenderTimeoutError
} from "@testing-library/react-render-stream";
// src/assertable.ts
var assertableSymbol = Symbol.for(
"@testing-library/react-render-stream:assertable"
);
// src/expect/renderStreamMatchers.ts
var toRerender = async function toRerender2(actual, options) {
const _stream = actual;
const stream = assertableSymbol in _stream ? _stream[assertableSymbol] : _stream;
const hint = this.utils.matcherHint("toRerender", void 0, void 0, {
isNot: this.isNot
});
let pass = true;
try {
await stream.peekRender({ timeout: 100, ...options });
} catch (e) {
if (e instanceof WaitForRenderTimeoutError) {
pass = false;
} else {
throw e;
}
}
return {
pass,
message() {
return `${hint}
Expected component to${pass ? " not" : ""} rerender, but it did${pass ? "" : " not"}.`;
}
};
};
var failed = new Error();
var toRenderExactlyTimes = async function toRenderExactlyTimes2(actual, times, optionsPerRender) {
const _stream = actual;
const stream = assertableSymbol in _stream ? _stream[assertableSymbol] : _stream;
const options = { timeout: 100, ...optionsPerRender };
const hint = this.utils.matcherHint(
"toRenderExactlyTimes",
void 0,
void 0,
{ isNot: this.isNot }
);
let pass = true;
try {
if (stream.totalRenderCount() > times) {
throw failed;
}
try {
while (stream.totalRenderCount() < times) {
await stream.waitForNextRender(options);
}
} catch (e) {
throw e instanceof WaitForRenderTimeoutError ? failed : e;
}
try {
await stream.waitForNextRender(options);
} catch (e) {
if (!(e instanceof WaitForRenderTimeoutError)) {
throw e;
}
}
} catch (e) {
if (e === failed) {
pass = false;
} else {
throw e;
}
}
return {
pass,
message() {
return `${hint}
Expected component to${pass ? " not" : ""} render exactly ${times} times.
It rendered ${stream.totalRenderCount()} times.`;
}
};
};
// src/expect/index.ts
expect.extend({
toRerender,
toRenderExactlyTimes
});
//# sourceMappingURL=expect.js.map