‹ 首页

jasmine-skill

@lambdatest · 收录于 1 周前 · 上游提交 4 周前★ 社区精选

Generates 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".

适合你,如果正在用 Jasmine 写 JavaScript 测试

/ 通过 npx 安装 校验哈希
npx oh-my-skill add lambdatest/agent-skills/jasmine-skill
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- lambdatest/agent-skills/jasmine-skill
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify lambdatest/agent-skills/jasmine-skill
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
323GitHub stars
~765最小装载
~4.4K含声明引用
~5.1K文本包总量
索引托管

怎么用

技能原文 SKILL.md作者撰写 · MIT · 54824d6

Jasmine Testing Skill

Core Patterns
Basic Test
describe('Calculator', () => {
  let calc;

  beforeEach(() => { calc = new Calculator(); });

  it('should add two numbers', () => {
    expect(calc.add(2, 3)).toBe(5);
  });

  it('should throw on divide by zero', () => {
    expect(() => calc.divide(10, 0)).toThrowError('Division by zero');
  });
});
Matchers
expect(value).toBe(exact);              // === strict
expect(value).toEqual(object);           // Deep equality
expect(value).toBeTruthy();
expect(value).toBeFalsy();
expect(value).toBeNull();
expect(value).toBeUndefined();
expect(value).toBeDefined();
expect(value).toBeNaN();
expect(value).toBeGreaterThan(3);
expect(value).toBeCloseTo(0.3, 5);
expect(str).toContain('sub');
expect(str).toMatch(/pattern/);
expect(arr).toContain(item);
expect(fn).toThrow();
expect(fn).toThrowError('message');

// Negation
expect(value).not.toBe(other);
Spies
describe('UserService', () => {
  let service, api;

  beforeEach(() => {
    api = jasmine.createSpyObj('api', ['get', 'post']);
    service = new UserService(api);
  });

  it('fetches user from API', async () => {
    api.get.and.returnValue(Promise.resolve({ name: 'Alice' }));
    const user = await service.getUser(1);
    expect(user.name).toBe('Alice');
    expect(api.get).toHaveBeenCalledWith('/users/1');
    expect(api.get).toHaveBeenCalledTimes(1);
  });
});

// Spy on existing method
spyOn(obj, 'method').and.returnValue(42);
spyOn(obj, 'method').and.callThrough();    // Call original
spyOn(obj, 'method').and.throwError('err');
Async Testing
it('fetches data', async () => {
  const data = await fetchData();
  expect(data).toBeDefined();
});

// With done callback
it('fetches data', (done) => {
  fetchData().then(data => {
    expect(data).toBeDefined();
    done();
  });
});

// Clock control
beforeEach(() => { jasmine.clock().install(); });
afterEach(() => { jasmine.clock().uninstall(); });

it('handles timeout', () => {
  const callback = jasmine.createSpy();
  setTimeout(callback, 1000);
  jasmine.clock().tick(1001);
  expect(callback).toHaveBeenCalled();
});
Setup: npm install jasmine --save-dev && npx jasmine init
Run: npx jasmine or npx jasmine spec/calculatorSpec.js
Deep Patterns

See reference/playbook.md for production-grade patterns:

| Section | What You Get | |---------|-------------| | §1 Project Setup | jasmine.json, TypeScript, spec reporter config | | §2 Spies — Complete API | spyOn, createSpyObj, callFake, returnValues, call tracking | | §3 Async Testing | async/await, expectAsync, promise matchers | | §4 Custom Matchers | Domain-specific matchers, asymmetric matchers | | §5 Test Organization | Nested describe, shared state, focused/excluded | | §6 Fetch & Module Mocking | globalThis.fetch spy, HTTP error handling | | §7 Browser Testing | DOM creation, keyboard events, focus trapping with Karma | | §8 CI/CD Integration | GitHub Actions with coverage, browser testing | | §9 Debugging Table | 12 common problems with causes and fixes | | §10 Best Practices | 14-item checklist for production Jasmine testing |

按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。