diff --git a/packages/lib/src/components/Script.test.tsx b/packages/lib/src/components/Script.test.tsx new file mode 100644 index 00000000..4450214c --- /dev/null +++ b/packages/lib/src/components/Script.test.tsx @@ -0,0 +1,171 @@ +import React, { ReactNode, useEffect, useRef } from 'react'; +import { render } from '@testing-library/react'; +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import { Script } from './Script'; +import { Entity } from '../Entity'; +import { Script as PcScript } from 'playcanvas'; +import { Application } from '../Application'; +import { SubclassOf } from '../utils/types-utils'; + +const renderWithProviders = (ui: ReactNode) => { + return render( + + + {ui} + + + ); +}; + +describe('Script Component', () => { + beforeEach(() => { + vi.clearAllMocks(); + vi.stubEnv('NODE_ENV', 'development'); + }); + + afterEach(() => { + vi.unstubAllEnvs(); + }); + + it('should pass props to the script instance', () => { + const speed = 2; + const str = 'test'; + const direction = [1, 0, 0]; + + class TestingScript extends PcScript { + speed: number; + direction: number[]; + str: string; + + initialize() { + expect(this.speed).toBe(speed); + expect(this.direction).toEqual(direction); + expect(this.str).toBe(str); + } + } + + renderWithProviders(