# karma-typescript-mock

> karma-typescript mocker

Latest version **1.0.1** (published 2017-11-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install karma-typescript-mock
pnpm add karma-typescript-mock
yarn add karma-typescript-mock
bun add karma-typescript-mock
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2017-11-13 |
| First published | 2017-07-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Alex Jones |
| Maintainers | decisiontech |
| Keywords | decisiontech, karma, unit test, typescript, karma-typescript |

## Links

- npm: https://www.npmjs.com/package/karma-typescript-mock
- Repository: https://github.com/DecisionTechnologies/karma-typescript-mock
- Homepage: https://github.com/DecisionTechnologies/karma-typescript-mock#readme
- Issues: https://github.com/DecisionTechnologies/karma-typescript-mock/issues
- npm.io page: https://npm.io/package/karma-typescript-mock

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2017-11-13
- 1.0.0 — 2017-07-18

## README

# karma-typescript-mock
* Mock imported modules when using [karma-typescript](https://github.com/monounity/karma-typescript/)

## Installation

```
npm install --save-dev karma-typescript-mock
```

# Example
```
    import { KarmaTypescriptMocker } from "karma-typescript-mock";
    var KarmaTypescriptMocker = new KarmaTypescriptMocker();
    let restore = KarmaTypescriptMocker.mock('qs', { parse: ()=>()=>"result"})
    restore();
```

##### Methods
* mock
* mockExport
* restoreAll

##### Notes
* When passing in a function then it must be wrapped in another function e.g. ()=>{ spy = x; return mockFunc}


## Using with Jasmine
```
    import { JasmineKarmaTypeScriptMocker } from "karma-typescript-mock-jasmine";
    describe('Test', ()=>{
        JasmineKarmaTypeScriptMocker('qs', { parse: ()=>()=>"result})
        it('it', ()=>{

        })
    })
```

```
    import { JasmineKarmaTypeScriptMockerSingle } from "karma-typescript-mock-jasmine";
    describe('Test', ()=>{
        JasmineKarmaTypeScriptMockerSingle('qs', parse',  ()=>()=>"result)
        it('it', ()=>{
            
        })
    })
```

## Names you can use as a module to mock
##### Local file
* KarmaTypescriptMocker.mock('**C:/projects/karma-typescript-mock/src/bar.ts**'
* KarmaTypescriptMocker.mock('**src/bar.ts**'
* KarmaTypescriptMocker.mock('**src/bar.ts**'
* KarmaTypescriptMocker.mock('**src/bar**'
* KarmaTypescriptMocker.mock('**./src/bar.ts**'
* KarmaTypescriptMocker.mock('**./src/bar**'
* KarmaTypescriptMocker.mock('**./bar.ts**'
* KarmaTypescriptMocker.mock('**./bar**
##### npm module
* KarmaTypescriptMocker.mock('**query-string**'
##### private npm module
* KarmaTypescriptMocker.mock('**@private/custom**'


## Limitations
* cannot mock exported primitive values like strings
* cannot mock if import is a function e.g. cookies-js
* cannot mock if import is executed immedidately

---
_Source: https://npm.io/package/karma-typescript-mock · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
