├── .babelrc ├── .gitignore ├── .npmignore ├── test ├── .eslintrc └── test.js ├── src ├── .eslintrc └── index.js ├── .travis.yml ├── .editorconfig ├── mock.js ├── CHANGELOG.md ├── LICENSE ├── package.json └── README.md /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["react-native"] 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .npm-debug.log* 3 | build 4 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .babelrc 2 | CONTRIBUTING.md 3 | .eslintrc 4 | .gitignore 5 | test/ 6 | .travis.yml 7 | -------------------------------------------------------------------------------- /test/.eslintrc: -------------------------------------------------------------------------------- 1 | --- 2 | "extends": 3 | - "formidable/configurations/es6-react" 4 | 5 | "rules": 6 | "no-magic-numbers": 0 7 | -------------------------------------------------------------------------------- /src/.eslintrc: -------------------------------------------------------------------------------- 1 | --- 2 | "extends": 3 | - "formidable/configurations/es6-react" 4 | 5 | "rules": 6 | "no-magic-numbers": 0 7 | "no-arrow-condition": 0 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - "4" 5 | - "6" 6 | 7 | sudo: false 8 | 9 | before_install: 10 | - 'npm install -g npm@3' 11 | 12 | script: 13 | - 'npm run lint' 14 | - 'npm run test' 15 | 16 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | max_line_length = 100 12 | 13 | [*.md] 14 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /mock.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var ReactNativeSvgMock = require("./build/index"); 4 | 5 | // the cache key that real react-native-svg would get 6 | var key = require.resolve("react-native-svg"); 7 | 8 | // make sure the cache is filled with our lib 9 | require.cache[key] = { 10 | id: key, 11 | filename: key, 12 | loaded: true, 13 | exports: ReactNativeSvgMock 14 | }; 15 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # react-native-svg-mock changelog 2 | 3 | ## 2.0.0 (2017-11-09) 4 | 5 | Update dependencies and test infrastructure for React 16 and React Native 0.50.0 compat 6 | 7 | ## 1.1.0 (2017-06-15) 8 | 9 | Add `TSpan` and `TextPath` mocks. Update `react-*` dependencies. 10 | 11 | ## 1.0.2 (2016-08-10) 12 | 13 | Fix automock path 14 | 15 | ## 1.0.1 (2016-08-10) 16 | 17 | Fix default export 18 | 19 | ## 1.0.0 (2016-08-10) 20 | 21 | Initial release 22 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | 2 | var React = require("react"); 3 | var ReactNativeSvg = require("../"); 4 | 5 | var expect = require("chai").expect; 6 | var enzyme = require("enzyme"); 7 | var Adapter = require("enzyme-adapter-react-16"); 8 | 9 | enzyme.configure({ adapter: new Adapter() }); 10 | 11 | describe("mock", function () { 12 | it("requires", function () { 13 | expect(Object.keys(ReactNativeSvg)).to.have.length.above(1); 14 | }); 15 | 16 | it("renders", function () { 17 | for (var prop in ReactNativeSvg) { 18 | var comp = ReactNativeSvg[prop]; 19 | enzyme.render(React.createElement(comp)); 20 | } 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Formidable Labs 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-svg-mock", 3 | "version": "2.0.0", 4 | "description": "A mock implementation of react-native-svg for use in tests.", 5 | "main": "build/index.js", 6 | "scripts": { 7 | "lint": "eslint src", 8 | "mocha": "mocha --require babel-core/register test/test.js", 9 | "test": "npm run lint && npm run build && npm run mocha", 10 | "build": "babel src --out-dir build", 11 | "prepublish": "npm run build" 12 | }, 13 | "keywords": [ 14 | "react", 15 | "react-native", 16 | "react-native-svg", 17 | "mock", 18 | "testing" 19 | ], 20 | "repository": { 21 | "type": "git", 22 | "url": "git+https://github.com/FormidableLabs/react-native-svg-mock.git" 23 | }, 24 | "author": "Brian Mathews ", 25 | "license": "MIT", 26 | "bugs": { 27 | "url": "https://github.com/FormidableLabs/react-native-svg-mock/issues" 28 | }, 29 | "homepage": "https://github.com/FormidableLabs/react-native-svg-mock#readme", 30 | "devDependencies": { 31 | "babel": "^6.5.2", 32 | "babel-cli": "^6.11.4", 33 | "babel-core": "^6.13.2", 34 | "babel-eslint": "^6.1.2", 35 | "babel-preset-react-native": "^1.9.0", 36 | "chai": "^3.5.0", 37 | "enzyme": "^3.1.0", 38 | "enzyme-adapter-react-16": "^1.0.3", 39 | "eslint": "^2.0.0", 40 | "eslint-config-formidable": "^2.0.1", 41 | "eslint-plugin-filenames": "^1.2.0", 42 | "eslint-plugin-import": "^2.2.0", 43 | "eslint-plugin-react": "^6.10.3", 44 | "mocha": "^3.0.2", 45 | "prop-types": "^15.5.8", 46 | "react": "^16.0.0", 47 | "react-dom": "^16.0.0", 48 | "react-native": "^0.50.0" 49 | }, 50 | "peerDependencies": { 51 | "react": "*", 52 | "react-native": "*" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import PropTypes from "prop-types"; 3 | 4 | // Create a vanilla SVG component 5 | const createComponent = function (name) { 6 | return class extends React.Component { 7 | static displayName =name 8 | 9 | static propTypes = { 10 | children: PropTypes.node 11 | } 12 | 13 | render() { 14 | const type = name[0].toLowerCase() + name.substr(1); 15 | return React.createElement(type, this.props, this.props.children); 16 | } 17 | }; 18 | }; 19 | 20 | // Mock all react-native-svg exports 21 | // from https://github.com/magicismight/react-native-svg/blob/master/index.js 22 | const Svg = createComponent("Svg"); 23 | const Circle = createComponent("Circle"); 24 | const Ellipse = createComponent("Ellipse"); 25 | const G = createComponent("G"); 26 | const Text = createComponent("Text"); 27 | const TextPath = createComponent("TextPath"); 28 | const TSpan = createComponent("TSpan"); 29 | const Path = createComponent("Path"); 30 | const Polygon = createComponent("Polygon"); 31 | const Polyline = createComponent("Polyline"); 32 | const Line = createComponent("Line"); 33 | const Rect = createComponent("Rect"); 34 | const Use = createComponent("Use"); 35 | const Image = createComponent("Image"); 36 | const Symbol = createComponent("Symbol"); 37 | const Defs = createComponent("Defs"); 38 | const LinearGradient = createComponent("LinearGradient"); 39 | const RadialGradient = createComponent("RadialGradient"); 40 | const Stop = createComponent("Stop"); 41 | const ClipPath = createComponent("ClipPath"); 42 | 43 | export { 44 | Svg, 45 | Circle, 46 | Ellipse, 47 | G, 48 | Text, 49 | TextPath, 50 | TSpan, 51 | Path, 52 | Polygon, 53 | Polyline, 54 | Line, 55 | Rect, 56 | Use, 57 | Image, 58 | Symbol, 59 | Defs, 60 | LinearGradient, 61 | RadialGradient, 62 | Stop, 63 | ClipPath 64 | }; 65 | 66 | export default Svg; 67 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.com/FormidableLabs/react-native-svg-mock.svg?branch=master)](https://travis-ci.com/FormidableLabs/react-native-svg-mock) [![npm version](https://badge.fury.io/js/react-native-svg-mock.svg)](https://badge.fury.io/js/react-native-svg-mock) 2 | 3 | # react-native-svg-mock 4 | 5 | A mock implementation of [react-native-svg](https://github.com/magicismight/react-native-svg) for use in tests. Inspired by [react-native-mock](https://github.com/lelandrichardson/react-native-mock). 6 | 7 | ## Install 8 | 9 | With npm, do: 10 | 11 | ```sh 12 | npm install react-native-svg-mock --save-dev 13 | ``` 14 | 15 | ## Usage 16 | ```js 17 | /* file-that-runs-before-all-of-my-tests.js */ 18 | 19 | // This will mutate `react-native-svg`'s require cache with `react-native-svg-mock`'s. 20 | require('react-native-svg-mock/mock'); // <-- side-effects!!! 21 | ``` 22 | 23 | Or, with something like [Mockery](https://github.com/mfncooper/mockery), do: 24 | 25 | ```js 26 | import mockery from "mockery"; 27 | import reactNativeSvgMock from "react-native-svg-mock"; 28 | 29 | mockery.enable(); 30 | mockery.registerMock("react-native-svg", reactNativeSvgMock); 31 | ``` 32 | 33 | In a test with [Enzyme](https://github.com/airbnb/enzyme) and [Mocha](https://github.com/mochajs/mocha), this could look like: 34 | 35 | ```jsx 36 | import "react-native-mock/mock"; 37 | import "react-native-svg-mock/mock"; 38 | 39 | import { render } from "enzyme"; 40 | import { expect } from "chai"; 41 | 42 | import { VictoryChart } from "victory-native"; 43 | 44 | describe("", function () { 45 | it("should render", function () { 46 | var component = render(); 47 | expect(component).to.have.length(1); 48 | }); 49 | }); 50 | ``` 51 | 52 | 53 | ## Maintenance Status 54 | 55 | **Archived:** This project is no longer maintained by Formidable. We are no longer responding to issues or pull requests unless they relate to security concerns. We encourage interested developers to fork this project and make it their own! 56 | --------------------------------------------------------------------------------