刘光辉
10 小时以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { describe, expect, it } from 'vitest';
 
import { getScriptFunc } from './common';
 
describe('getScriptFunc', () => {
  it('accepts async button scripts', async () => {
    const script = getScriptFunc('async ({ value }) => await Promise.resolve(value)');
 
    expect(typeof script).toBe('function');
    expect(await script({ value: 'reprint' })).toBe('reprint');
  });
 
  it('rejects non-functions and invalid scripts', () => {
    expect(getScriptFunc('({ value: 1 })')).toBe(false);
    expect(getScriptFunc('not valid javascript')).toBe(false);
  });
});