quasqui
Version:
The meta-framework suite designed from scratch for frontend-focused modern web development.
65 lines (61 loc) • 1.37 kB
text/typescript
import { createImportStatements } from '../src/generateCode';
describe('generate code', () => {
test('should create import statements sucessfully', () => {
const statement = createImportStatements([
{
value: 'react',
specifiers: [
{
local: 'React',
},
{
imported: 'useState',
},
{
imported: 'useEffect',
},
],
},
]);
expect(statement).toEqual(
`import React, { useState, useEffect } from 'react';\n`,
);
});
test('should merge statements', () => {
const statement = createImportStatements([
{
value: 'a',
specifiers: [
{
local: 'b',
imported: 'c',
},
],
},
{
value: 'a',
specifiers: [
{
imported: 'd',
},
],
},
]);
expect(statement).toEqual(`import { c as b, d } from 'a';\n\n`);
});
test(`should create import statement with initilize string`, () => {
expect(
createImportStatements([
{
value: 'a',
specifiers: [
{
local: 'a',
},
],
initialize: 'console.log(a);',
},
]),
).toEqual(`import a from 'a';\nconsole.log(a);`);
});
});