Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mock-async-storage

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mock-async-storage - npm Package Compare versions

Comparing version 1.0.3 to 2.0.0

4

.vscode/settings.json
{
"vsicons.presets.angular": false
"flow.enabled": true,
"flow.useNPMPackagedFlow": true,
"javascript.validate.enable": false
}

@@ -6,3 +6,2 @@ 'use strict';

});
exports.release = exports.mock = undefined;

@@ -15,4 +14,2 @@ var _mockAsyncStorage = require('./mockAsyncStorage');

exports.default = _mockAsyncStorage2.default;
exports.mock = _mockAsyncStorage.mock;
exports.release = _mockAsyncStorage.release;
exports.default = _mockAsyncStorage2.default;

@@ -6,3 +6,2 @@ 'use strict';

});
exports.release = exports.mock = undefined;

@@ -17,3 +16,3 @@ var _deepmerge = require('deepmerge');

/* global jest Iterable */
/* global Iterable */

@@ -173,9 +172,2 @@ const isStringified = str => {

const mock = exports.mock = () => {
const mockImpl = new AsyncStorageMock();
jest.mock('AsyncStorage', () => mockImpl);
};
const release = exports.release = () => jest.unmock('AsyncStorage');
exports.default = AsyncStorageMock;
{
"name": "mock-async-storage",
"title": "Jest Mock AsyncStorage for react-native",
"version": "1.0.3",
"version": "2.0.0",
"description": "Its a mock of react-native AsyncStorage for jest tests",

@@ -50,9 +50,12 @@ "main": "lib/index.js",

"scripts": {
"tdd": "jest --watch",
"tdd": "jest src/** --watch",
"lint": "standard src/*.js src/**/*.js",
"test:src": "jest",
"test": "npm run lint && npm run test:src",
"test:src": "jest src/**",
"test": "npm run lint && npm run test:src && npm run examples",
"build": "babel src --out-dir lib --ignore spec.js",
"projectz": "projectz compile",
"compile": "npm run lint && npm run build && npm run projectz",
"example-jest": "jest ./examples/with-jest/**",
"example-sinon": "jest ./examples/with-sinon/**",
"examples": "npm run example-jest && npm run example-sinon",
"prepublish": "npm run build"

@@ -74,2 +77,3 @@ },

"jest": "^18.0.0",
"sinon": "^4.0.0",
"standard": "^8.6.0"

@@ -76,0 +80,0 @@ },

@@ -45,5 +45,82 @@ <!-- TITLE/ -->

<h1>mock-async-storage@beta</h1>
<h1>Usage</h1>
<h2>Whats the main difference?</h2>
<p>
I removed the jest specific part from the mock lib. In the next version
the mocking method is not predefined. You can use any kind of library (sinon) for use this mock.
</p>
<h2>Usage</h2>
<h3>Manual mocks</h3>
<p>
I suggest to use jest manual mocks <a href="https://facebook.github.io/jest/docs/en/manual-mocks.html">
Jest Manual Mocks
</a>
For demonstrate this solution you can find an example in examples folder.
<p>
<h3>Another mocking solution</h3>
```JavaScript
const MockAsyncStorage = require('mock-async-storage');
// or import { mock, release } from 'mock-async-storage';
// mock();
// release();
const mock = () => {
const mockImpl = new MockAsyncStorage()
jest.mock('AsyncStorage', () => mockImpl)
}
const release = () => jest.unmock('AsyncStorage')
mock();
// For unmock
mockStorage.release();
```
Working example:
```JavaScript
import 'react-native';
import MockAsyncStorage from 'mock-async-storage'
import React from 'react';
import Index from '../index.android.js';
// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';
const mock = () => {
const mockImpl = new MockAsyncStorage()
jest.mock('AsyncStorage', () => mockImpl)
}
mock();
import { AsyncStorage as storage } from 'react-native'
it('renders correctly', () => {
const tree = renderer.create(
<Index />
);
});
it('Mock Async Storage working', async () => {
await storage.setItem('myKey', 'myValue')
const value = await storage.getItem('myKey')
expect(value).toBe('myValue')
})
```
<h1>mock-async-storage</h1>
<p>This is for the current verison</p>
<h2>Usage</h2>
In your test codes:

@@ -50,0 +127,0 @@

@@ -1,8 +0,3 @@

import AsyncStorageMock, { mock, release } from './mockAsyncStorage'
import AsyncStorageMock from './mockAsyncStorage'
export default AsyncStorageMock
export {
mock,
release
}
// @flow
/* global jest Iterable */
/* global Iterable */

@@ -127,9 +127,2 @@ import merge from 'deepmerge'

export const mock = () => {
const mockImpl = new AsyncStorageMock()
jest.mock('AsyncStorage', () => mockImpl)
}
export const release = () => jest.unmock('AsyncStorage')
export default AsyncStorageMock

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc