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

composable-form-tests

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

composable-form-tests - npm Package Compare versions

Comparing version 0.2.0 to 1.0.0

178

dist/testInput.js

@@ -29,3 +29,7 @@ "use strict";

simulateChanged = _ref.simulateChanged,
simulateSubmit = _ref.simulateSubmit;
simulateSubmit = _ref.simulateSubmit,
testGetValue = _ref.testGetValue,
testIsDirty = _ref.testIsDirty,
testResetValue = _ref.testResetValue,
testSetValue = _ref.testSetValue;

@@ -82,13 +86,2 @@ var inputName = Input.name;

if (typeof simulateSubmit === 'function') {
test(inputName + " calls onSubmit", function () {
var onSubmit = jest.fn();
var wrapper = mount(_react2.default.createElement(Input, _extends({ name: "test", onSubmit: onSubmit, options: options }, props)));
simulateSubmit(wrapper);
expect(onSubmit).toHaveBeenCalledTimes(1);
});
}
test(inputName + " calls onChanging followed by onChange when the value prop changes", function () {

@@ -111,100 +104,119 @@ var onChanging = jest.fn();

test(inputName + " getValue", function () {
var wrapper = mount(_react2.default.createElement(Input, _extends({ name: "test", value: exampleValueOne, options: options }, props)));
if (typeof simulateSubmit === 'function') {
test(inputName + " calls onSubmit", function () {
var onSubmit = jest.fn();
// Inputs can optionally have an getValue method
if (typeof wrapper.instance().getValue !== 'function') {
expect(true).toBe(true);
return;
}
var wrapper = mount(_react2.default.createElement(Input, _extends({ name: "test", onSubmit: onSubmit, options: options }, props)));
simulateSubmit(wrapper);
expect(wrapper.instance().getValue()).toEqual(exampleValueOne);
expect(onSubmit).toHaveBeenCalledTimes(1);
});
}
wrapper.setProps({ value: exampleValueTwo });
expect(wrapper.instance().getValue()).toEqual(exampleValueTwo);
if (testGetValue === true) {
test(inputName + " getValue", function () {
var wrapper = mount(_react2.default.createElement(Input, _extends({ name: "test", value: exampleValueOne, options: options }, props)));
simulateChanged(wrapper, exampleValueOne);
expect(wrapper.instance().getValue()).toEqual(exampleValueOne);
});
// Inputs can optionally have an getValue method
if (typeof wrapper.instance().getValue !== 'function') {
expect(true).toBe(true);
return;
}
test(inputName + " isDirty", function () {
var wrapper = mount(_react2.default.createElement(Input, _extends({ name: "test", value: exampleValueOne, options: options }, props)));
expect(wrapper.instance().getValue()).toEqual(exampleValueOne);
// Inputs can optionally have an isDirty method
if (typeof wrapper.instance().isDirty !== 'function') {
expect(true).toBe(true);
return;
}
wrapper.setProps({ value: exampleValueTwo });
expect(wrapper.instance().getValue()).toEqual(exampleValueTwo);
expect(wrapper.instance().isDirty()).toBe(false);
simulateChanged(wrapper, exampleValueOne);
expect(wrapper.instance().getValue()).toEqual(exampleValueOne);
});
}
// Should only be true if changed by user rather than by prop
wrapper.setProps({ value: exampleValueTwo });
expect(wrapper.instance().isDirty()).toBe(false);
if (testIsDirty === true) {
test(inputName + " isDirty", function () {
var wrapper = mount(_react2.default.createElement(Input, _extends({ name: "test", value: exampleValueOne, options: options }, props)));
simulateChanged(wrapper, exampleValueOne);
expect(wrapper.instance().isDirty()).toBe(true);
});
// Inputs can optionally have an isDirty method
if (typeof wrapper.instance().isDirty !== 'function') {
expect(true).toBe(true);
return;
}
test(inputName + " resetValue works and calls onChanging and onChange", function () {
var onChanging = jest.fn();
var onChange = jest.fn();
expect(wrapper.instance().isDirty()).toBe(false);
var wrapper = mount(_react2.default.createElement(Input, _extends({ name: "test", onChanging: onChanging, onChange: onChange, value: exampleValueOne, options: options }, props)));
// Should only be true if changed by user rather than by prop
wrapper.setProps({ value: exampleValueTwo });
expect(wrapper.instance().isDirty()).toBe(false);
// Inputs can optionally have an getValue and resetValue methods
if (typeof wrapper.instance().getValue !== 'function' || typeof wrapper.instance().resetValue !== 'function') {
expect(true).toBe(true);
return;
}
simulateChanged(wrapper, exampleValueOne);
expect(wrapper.instance().isDirty()).toBe(true);
});
}
expect(wrapper.instance().getValue()).toEqual(exampleValueOne);
if (testResetValue === true) {
test(inputName + " resetValue works and calls onChanging and onChange", function () {
var onChanging = jest.fn();
var onChange = jest.fn();
simulateChanged(wrapper, exampleValueTwo);
expect(wrapper.instance().getValue()).toEqual(exampleValueTwo);
var wrapper = mount(_react2.default.createElement(Input, _extends({ name: "test", onChanging: onChanging, onChange: onChange, value: exampleValueOne, options: options }, props)));
onChanging.mockClear();
onChange.mockClear();
// Inputs can optionally have an getValue and resetValue methods
if (typeof wrapper.instance().getValue !== 'function' || typeof wrapper.instance().resetValue !== 'function') {
expect(true).toBe(true);
return;
}
wrapper.instance().resetValue();
expect(wrapper.instance().getValue()).toEqual(exampleValueOne);
expect(wrapper.instance().getValue()).toEqual(exampleValueOne);
expect(onChanging).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenCalledTimes(1);
simulateChanged(wrapper, exampleValueTwo);
expect(wrapper.instance().getValue()).toEqual(exampleValueTwo);
expect(onChanging).toHaveBeenLastCalledWith(exampleValueOne);
expect(onChange).toHaveBeenLastCalledWith(exampleValueOne);
});
onChanging.mockClear();
onChange.mockClear();
test(inputName + " setValue works and calls onChanging and onChange", function () {
var onChanging = jest.fn();
var onChange = jest.fn();
wrapper.instance().resetValue();
expect(wrapper.instance().getValue()).toEqual(exampleValueOne);
var wrapper = mount(_react2.default.createElement(Input, _extends({ name: "test", onChanging: onChanging, onChange: onChange, value: exampleValueOne, options: options }, props)));
expect(onChanging).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenCalledTimes(1);
// Inputs can optionally have getValue and setValue methods
if (typeof wrapper.instance().getValue !== 'function' || typeof wrapper.instance().setValue !== 'function') {
expect(true).toBe(true);
return;
}
expect(onChanging).toHaveBeenLastCalledWith(exampleValueOne);
expect(onChange).toHaveBeenLastCalledWith(exampleValueOne);
});
}
expect(wrapper.instance().getValue()).toEqual(exampleValueOne);
if (testSetValue === true) {
test(inputName + " setValue works and calls onChanging and onChange", function () {
var onChanging = jest.fn();
var onChange = jest.fn();
onChanging.mockClear();
onChange.mockClear();
var wrapper = mount(_react2.default.createElement(Input, _extends({ name: "test", onChanging: onChanging, onChange: onChange, value: exampleValueOne, options: options }, props)));
wrapper.instance().setValue(exampleValueTwo);
expect(wrapper.instance().getValue()).toEqual(exampleValueTwo);
// Inputs can optionally have getValue and setValue methods
if (typeof wrapper.instance().getValue !== 'function' || typeof wrapper.instance().setValue !== 'function') {
expect(true).toBe(true);
return;
}
// Inputs can optionally have an isDirty method
if (typeof wrapper.instance().isDirty === 'function') {
expect(wrapper.instance().isDirty()).toBe(true);
}
expect(wrapper.instance().getValue()).toEqual(exampleValueOne);
expect(onChanging).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenCalledTimes(1);
onChanging.mockClear();
onChange.mockClear();
expect(onChanging).toHaveBeenLastCalledWith(exampleValueTwo);
expect(onChange).toHaveBeenLastCalledWith(exampleValueTwo);
});
wrapper.instance().setValue(exampleValueTwo);
expect(wrapper.instance().getValue()).toEqual(exampleValueTwo);
// Inputs can optionally have an isDirty method
if (typeof wrapper.instance().isDirty === 'function') {
expect(wrapper.instance().isDirty()).toBe(true);
}
expect(onChanging).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenCalledTimes(1);
expect(onChanging).toHaveBeenLastCalledWith(exampleValueTwo);
expect(onChange).toHaveBeenLastCalledWith(exampleValueTwo);
});
}
}
{
"name": "composable-form-tests",
"version": "0.2.0",
"version": "1.0.0",
"description": "Tests for Composable Form Spec components written in React",

@@ -5,0 +5,0 @@ "author": "Dairy State Designs (http://dairystatedesigns.com/)",

@@ -41,2 +41,6 @@ # Composable Form Tests

| simulateSubmit | OPTIONAL. If your input ever calls `onSubmit`, use this function to simulate one user action that will cause it to happen. |
| testGetValue | OPTIONAL. Default is `false`. Set to `true` to add a test for the `getValue()` instance function
| testIsDirty | OPTIONAL. Default is `false`. Set to `true` to add a test for the `isDirty()` instance function
| testResetValue | OPTIONAL. Default is `false`. Set to `true` to add a test for the `resetValue()` instance function
| testSetValue | OPTIONAL. Default is `false`. Set to `true` to add a test for the `setValue()` instance function

@@ -43,0 +47,0 @@ ### Basic Input Example

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