/
githubmirror
/
jest
Обзор
Документация
Войти
/
githubmirror
/
jest
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
examples/jquery/__tests__/display_user.test.js
37 строк
1 KB
fisker Cheung
chore: update ESLint to v9 (#15531)
05 мар 2025, 16:49
Не верифицирован
05 мар 2025, 16:49
4e7d916
Код
Авторство
О чём код?
// Copyright (c) Meta Platforms, Inc. and affiliates.. All Rights Reserved. 'use strict'; jest.mock('../fetchCurrentUser.js'); it('displays a user after a click', () => { // Set up our document body document.body.innerHTML = '<div>' + ' <span id="username" />' + ' <button id="button" />' + '</div>'; // This module has a side-effect require('../displayUser'); const $ = require('jquery'); const fetchCurrentUser = require('../fetchCurrentUser'); // Tell the fetchCurrentUser mock function to automatically invoke // its callback with some data fetchCurrentUser.mockImplementation(cb => { cb({ fullName: 'Johnny Cash', loggedIn: true, }); }); // Use jquery to emulate a click on our button $('#button').click(); // Assert that the fetchCurrentUser function was called, and that the // #username span's inner text was updated as we'd expect it to. expect(fetchCurrentUser).toHaveBeenCalled(); expect($('#username').text()).toBe('Johnny Cash - Logged In'); });