Skip to content

Instantly share code, notes, and snippets.

import { useEffect } from "react";
export const useSimpleChromeExtension = () => {
useEffect(() => {
if (!chrome.tabs) {
// Will be undefined if open app not as Chrome extension
return;
}
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
import { useEffect } from "react";
export const useSimpleChromeExtensionHook = () => {
useEffect(() => {
if (!chrome.tabs) {
// Will be undefined if open app not as Chrome extension
return;
}
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
import { useEffect } from "react";
export const useSimpleChromeExtensionHook = () => {
useEffect(() => {
// 1. Get the current active tab
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
console.log(">>>>>>>> chrome.tabs.query <<<<<<<<<< ", tabs);
const activeTabId = tabs[0].id as number;
// 2. Execute a script in that active tab
const OLD = {
image: { __typename__: 'Image' },
sprites: [
{ x: 0, y: 0, width: 2, height: 2 },
{ x: 0, y: 0, width: 2, height: 23 },
{ x: 0, y: 0, width: 2, height: 36 },
{ x: 0, y: 0, width: 2, height: 42 },
{ x: 0, y: 0, width: 2, height: 48 },
{ x: 0, y: 0, width: 2, height: 140 },
{ x: 0, y: 0, width: 2, height: 129 },
export const JSONContentMock: JSONContent = {
doc: {
type: 'doc',
content: [
{
type: 'heading',
attrs: { level: 1 },
content: [{ type: 'text', text: 'Title' }],
},
{
const students = [
{ name: 'Alice', age: 20, grade: 4.5 },
{ name: 'Bob', age: 21, grade: 3.9 },
{ name: 'Charlie', age: 19, grade: 4.8 },
];
const calculateAverageGrade = (studentArgument) => {
let result = 0;
// сумма всех баллов (версия 1)
import { ApolloClient, gql, useApolloClient } from '@apollo/client';
import Uppy from '@uppy/core';
// https://github.com/uuidjs/uuid#getrandomvalues-not-supported
import 'react-native-get-random-values';
import { v4 as uuidv4 } from 'uuid';
import { translateScalar } from '@landr/mfe/src/utils/translateScalar';
import { useMemo } from 'react';
import { FileUploaderProps } from '@landr/mfe';
import { useFileUploader } from '@landr/mfe/src/customHooks/useFileUploader';
import * as DocumentPicker from 'expo-document-picker';
expect(result.current.isTrue).toBe(false);
- await waitForNextUpdate();
+ await waitForNextUpdate({
+ timeout: 2500,
+ });
expect(result.current.isTrue).toBe(true);
});
useEffect(() => {
const id = setTimeout(() => {
setIsTrue(true);
- }, 1000);
+ }, 2000);
return () => {
clearTimeout(id);
import { renderHook, act } from '@testing-library/react-hooks';
import { useSimplestHook } from './1.simplest-hook';
it('should set to true', () => {
const { result } = renderHook(() => useSimplestHook());
expect(result.current.isTrue).toBe(false);
act(() => {
result.current.toggle();