@testing-library/react-render-stream
Version:
## What is this library?
93 lines (86 loc) • 2.38 kB
JavaScript
// src/expect/index.ts
var import_expect = require("expect");
// src/expect/renderStreamMatchers.ts
var import_react_render_stream = require("@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 import_react_render_stream.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 import_react_render_stream.WaitForRenderTimeoutError ? failed : e;
}
try {
await stream.waitForNextRender(options);
} catch (e) {
if (!(e instanceof import_react_render_stream.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
import_expect.expect.extend({
toRerender,
toRenderExactlyTimes
});
//# sourceMappingURL=expect.cjs.map
;