Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should detect potential issues with the TodoList', async () =>
await fc.assert(
fc
.asyncProperty(
fc.scheduler({ act }),
TodoListCommands,
fc.set(
fc.record({ id: fc.hexaString(8, 8), label: fc.string(), checked: fc.boolean() }),
(a, b) => a.id === b.id
),
fc.infiniteStream(fc.boolean()),
async (s, commands, initialTodos, allFailures) => {
const { mockedApi, expectedTodos } = mockApi(s, initialTodos, allFailures);
// Execute all the commands
const wrapper = render();
await fc.scheduledModelRun(s, () => ({ model: { todos: [], wrapper }, real: {} }), commands);
// Check the final state (no more items should be loading)
expect(
sortTodos(
it('should not display data related to another user (complex)', () =>
fc.assert(
fc
.asyncProperty(fc.array(fc.uuid(), 1, 10), fc.scheduler(), async (loadedUserIds, s) => {
// Arrange
const getUserProfileImplem = s.scheduleFunction(function getUserProfile(userId: string) {
return Promise.resolve({ id: userId, name: userId });
});
// Act
let currentUid = loadedUserIds[0];
const { rerender, queryByText, queryByTestId } = render(
);
s.scheduleSequence(
loadedUserIds.slice(1).map(uid => ({
label: `Update user id to ${uid}`,
builder: async () => {
currentUid = uid;
rerender();
it('should be able to compute a dependency tree for any package of the registry', () =>
fc.assert(
fc.asyncProperty(AllPackagesArbitrary, fc.scheduler(), async (packages, s) => {
// Arrange
const selectedPackage = Object.keys(packages)[0];
const fetch: (name: string) => Promise = s.scheduleFunction(function fetch(packageName) {
return Promise.resolve(packages[packageName]);
});
// Act
dependencyTree(selectedPackage, fetch); // without bugs
// dependencyTree(selectedPackage, fetch, true); // or with bugs
// Assert
let numQueries = 0;
while (s.count() !== 0) {
if (++numQueries > 2 * Object.keys(packages).length) {
throw new Error(`Too many queries`);
}
it('should suggest results matching the value of the autocomplete field', () =>
fc.assert(
fc
.asyncProperty(AllResultsArbitrary, QueriesArbitrary, fc.scheduler({ act }), async (allResults, queries, s) => {
// Arrange
const searchImplem: typeof search = s.scheduleFunction(function search(query, maxResults) {
return Promise.resolve(allResults.filter(r => r.includes(query)).slice(0, maxResults));
});
// Act
const { getByRole, queryAllByRole } = render();
const input = getByRole('input') as HTMLElement;
s.scheduleSequence(buildAutocompleteEvents(input, queries));
// Assert
while (s.count() !== 0) {
await s.waitOne();
const autocompletionValue = input.attributes.getNamedItem('value')!.value;
const suggestions = (queryAllByRole('listitem') as HTMLElement[]).map(getNodeText);
it('should not display data related to another user', () =>
fc.assert(
fc
.asyncProperty(fc.uuid(), fc.uuid(), fc.scheduler({ act }), async (uid1, uid2, s) => {
// Arrange
const getUserProfileImplem = s.scheduleFunction(function getUserProfile(userId: string) {
return Promise.resolve({ id: userId, name: userId });
});
// Act
const { rerender, queryByText, queryByTestId } = render(
);
s.scheduleSequence([
async () => {
rerender();
}
]);
await s.waitAll();