Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Gru Tester] Add unit test for src/babel/utils.ts #8

Open
wants to merge 1 commit into
base: gru-unit-test
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/babel/utils.gru.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unused-vars */
import * as babel from '@babel/core'
import { beforeEach, describe, expect, it } from 'vitest'
import type { PluginOptions } from './utils.ts'
import { isAtom } from './utils.ts'

describe('isAtom', () => {
let t: typeof babel.types

beforeEach(() => {
t = babel.types
})

it('should return true for core atom functions', () => {
const callee = t.identifier('atom')
expect(isAtom(t, callee)).toBe(true)
})

it('should return true for custom atom functions', () => {
const callee = t.identifier('customAtom')
const options: PluginOptions = { customAtomNames: ['customAtom'] }
expect(isAtom(t, callee, options.customAtomNames)).toBe(true)
})

it('should return false for non-atom functions', () => {
const callee = t.identifier('nonAtom')
expect(isAtom(t, callee)).toBe(false)
})

it('should return true for member expression with core atom function', () => {
const callee = t.memberExpression(t.identifier('obj'), t.identifier('atom'))
expect(isAtom(t, callee)).toBe(true)
})

it('should return true for member expression with custom atom function', () => {
const callee = t.memberExpression(
t.identifier('obj'),
t.identifier('customAtom'),
)
const options: PluginOptions = { customAtomNames: ['customAtom'] }
expect(isAtom(t, callee, options.customAtomNames)).toBe(true)
})

it('should return false for member expression with non-atom function', () => {
const callee = t.memberExpression(
t.identifier('obj'),
t.identifier('nonAtom'),
)
expect(isAtom(t, callee)).toBe(false)
})
})