$npx -y skills add LambdaTest/agent-skills --skill jasmine-skillGenerates Jasmine tests in JavaScript. BDD-style framework with spies and async support. Use when user mentions "Jasmine", "jasmine.createSpy", "toHaveBeenCalled". Triggers on: "Jasmine", "jasmine test", "createSpy", "Jasmine spec".
| 1 | # Jasmine Testing Skill |
| 2 | |
| 3 | ## Core Patterns |
| 4 | |
| 5 | ### Basic Test |
| 6 | |
| 7 | ```javascript |
| 8 | describe('Calculator', () => { |
| 9 | let calc; |
| 10 | |
| 11 | beforeEach(() => { calc = new Calculator(); }); |
| 12 | |
| 13 | it('should add two numbers', () => { |
| 14 | expect(calc.add(2, 3)).toBe(5); |
| 15 | }); |
| 16 | |
| 17 | it('should throw on divide by zero', () => { |
| 18 | expect(() => calc.divide(10, 0)).toThrowError('Division by zero'); |
| 19 | }); |
| 20 | }); |
| 21 | ``` |
| 22 | |
| 23 | ### Matchers |
| 24 | |
| 25 | ```javascript |
| 26 | expect(value).toBe(exact); // === strict |
| 27 | expect(value).toEqual(object); // Deep equality |
| 28 | expect(value).toBeTruthy(); |
| 29 | expect(value).toBeFalsy(); |
| 30 | expect(value).toBeNull(); |
| 31 | expect(value).toBeUndefined(); |
| 32 | expect(value).toBeDefined(); |
| 33 | expect(value).toBeNaN(); |
| 34 | expect(value).toBeGreaterThan(3); |
| 35 | expect(value).toBeCloseTo(0.3, 5); |
| 36 | expect(str).toContain('sub'); |
| 37 | expect(str).toMatch(/pattern/); |
| 38 | expect(arr).toContain(item); |
| 39 | expect(fn).toThrow(); |
| 40 | expect(fn).toThrowError('message'); |
| 41 | |
| 42 | // Negation |
| 43 | expect(value).not.toBe(other); |
| 44 | ``` |
| 45 | |
| 46 | ### Spies |
| 47 | |
| 48 | ```javascript |
| 49 | describe('UserService', () => { |
| 50 | let service, api; |
| 51 | |
| 52 | beforeEach(() => { |
| 53 | api = jasmine.createSpyObj('api', ['get', 'post']); |
| 54 | service = new UserService(api); |
| 55 | }); |
| 56 | |
| 57 | it('fetches user from API', async () => { |
| 58 | api.get.and.returnValue(Promise.resolve({ name: 'Alice' })); |
| 59 | const user = await service.getUser(1); |
| 60 | expect(user.name).toBe('Alice'); |
| 61 | expect(api.get).toHaveBeenCalledWith('/users/1'); |
| 62 | expect(api.get).toHaveBeenCalledTimes(1); |
| 63 | }); |
| 64 | }); |
| 65 | |
| 66 | // Spy on existing method |
| 67 | spyOn(obj, 'method').and.returnValue(42); |
| 68 | spyOn(obj, 'method').and.callThrough(); // Call original |
| 69 | spyOn(obj, 'method').and.throwError('err'); |
| 70 | ``` |
| 71 | |
| 72 | ### Async Testing |
| 73 | |
| 74 | ```javascript |
| 75 | it('fetches data', async () => { |
| 76 | const data = await fetchData(); |
| 77 | expect(data).toBeDefined(); |
| 78 | }); |
| 79 | |
| 80 | // With done callback |
| 81 | it('fetches data', (done) => { |
| 82 | fetchData().then(data => { |
| 83 | expect(data).toBeDefined(); |
| 84 | done(); |
| 85 | }); |
| 86 | }); |
| 87 | |
| 88 | // Clock control |
| 89 | beforeEach(() => { jasmine.clock().install(); }); |
| 90 | afterEach(() => { jasmine.clock().uninstall(); }); |
| 91 | |
| 92 | it('handles timeout', () => { |
| 93 | const callback = jasmine.createSpy(); |
| 94 | setTimeout(callback, 1000); |
| 95 | jasmine.clock().tick(1001); |
| 96 | expect(callback).toHaveBeenCalled(); |
| 97 | }); |
| 98 | ``` |
| 99 | |
| 100 | ## Setup: `npm install jasmine --save-dev && npx jasmine init` |
| 101 | ## Run: `npx jasmine` or `npx jasmine spec/calculatorSpec.js` |
| 102 | |
| 103 | ## Deep Patterns |
| 104 | |
| 105 | See `reference/playbook.md` for production-grade patterns: |
| 106 | |
| 107 | | Section | What You Get | |
| 108 | |---------|-------------| |
| 109 | | §1 Project Setup | jasmine.json, TypeScript, spec reporter config | |
| 110 | | §2 Spies — Complete API | spyOn, createSpyObj, callFake, returnValues, call tracking | |
| 111 | | §3 Async Testing | async/await, expectAsync, promise matchers | |
| 112 | | §4 Custom Matchers | Domain-specific matchers, asymmetric matchers | |
| 113 | | §5 Test Organization | Nested describe, shared state, focused/excluded | |
| 114 | | §6 Fetch & Module Mocking | globalThis.fetch spy, HTTP error handling | |
| 115 | | §7 Browser Testing | DOM creation, keyboard events, focus trapping with Karma | |
| 116 | | §8 CI/CD Integration | GitHub Actions with coverage, browser testing | |
| 117 | | §9 Debugging Table | 12 common problems with causes and fixes | |
| 118 | | §10 Best Practices | 14-item checklist for production Jasmine testing | |