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

@indoqa/test-utils

Package Overview
Dependencies
Maintainers
4
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@indoqa/test-utils - npm Package Compare versions

Comparing version 2.0.0-alpha.1 to 2.0.0-alpha.2

56

lib/fela/cssToObject.js
import css from 'css';
export var cssObjectToIStyle = function (cssObject, classNames, result, breakpointNames) {
export const cssObjectToIStyle = (cssObject, classNames, result, breakpointNames) => {
if (!classNames) {
return;
}
var classes = classNames.split(' ');
Object.keys(cssObject).forEach(function (key) {
var _a;
var value = cssObject[key];
const classes = classNames.split(' ');
Object.keys(cssObject).forEach((key) => {
const value = cssObject[key];
if (key.startsWith('.')) {
var className = key.substring(1);
const className = key.substring(1);
if (classes.includes(className)) {

@@ -17,30 +16,28 @@ Object.assign(result, value);

if (key.startsWith('@')) {
var mediaQueryRules = {};
const mediaQueryRules = {};
cssObjectToIStyle(value, classNames, mediaQueryRules, breakpointNames);
var breakpointName = breakpointNames[key] || key;
Object.assign(result, (_a = {}, _a[breakpointName] = mediaQueryRules, _a));
const breakpointName = breakpointNames[key] || key;
Object.assign(result, { [breakpointName]: mediaQueryRules });
}
});
};
export var cssToObject = function (cssString, opts) {
var ast = css.parse(cssString);
export const cssToObject = (cssString, opts) => {
const ast = css.parse(cssString);
if (ast && ast.stylesheet) {
return transform(opts)(ast.stylesheet.rules);
}
throw Error("The cssString could not be parsed: " + cssString);
throw Error(`The cssString could not be parsed: ${cssString}`);
};
var transform = function (opts) { return function (rules, result) {
if (result === void 0) { result = {}; }
rules.forEach(function (rule) {
var _a;
const transform = (opts) => (rules, result = {}) => {
rules.forEach((rule) => {
if (rule.type === 'media') {
var k = '@media ' + rule.media;
const k = '@media ' + rule.media;
result[k] = transform(opts)(rule.rules);
return;
}
var key = rule.selectors[0];
const [key] = rule.selectors;
if (key.length) {
Object.assign(result, (_a = {},
_a[key] = getDeclarations(rule.declarations, opts),
_a));
Object.assign(result, {
[key]: getDeclarations(rule.declarations, opts),
});
}

@@ -52,11 +49,10 @@ else {

return result;
}; };
var getDeclarations = function (decs, opts) {
if (opts === void 0) { opts = {}; }
};
const getDeclarations = (decs, opts = {}) => {
return decs
.map(function (d) { return ({
.map((d) => ({
key: opts.camelCase ? camel(d.property) : d.property,
value: opts.numbers ? parsePx(d.value) : d.value,
}); })
.reduce(function (a, b) {
}))
.reduce((a, b) => {
a[b.key] = b.value.valueOf();

@@ -66,11 +62,11 @@ return a;

};
var camel = function (str) {
const camel = (str) => {
if (str.startsWith('-')) {
return str;
}
return str.replace(/(-[a-z])/g, function (x) { return x.toUpperCase(); }).replace(/-/g, '');
return str.replace(/(-[a-z])/g, (x) => x.toUpperCase()).replace(/-/g, '');
};
var parsePx = function (val) {
const parsePx = (val) => {
return /px$/.test(val) ? parseFloat(val.replace(/px$/, '')) : val;
};
//# sourceMappingURL=cssToObject.js.map

@@ -10,3 +10,3 @@ import { toMinMediaQuery } from '@indoqa/style-system';

}
var style = getHtmlElementStyles(renderer, el, theme);
const style = getHtmlElementStyles(renderer, el, theme);
if (debug) {

@@ -18,13 +18,13 @@ console.log('Style', style);

export function expectCssPropertyValue(el, theme, property, expectedPropertyValue, breakpointName, debug) {
var actualPropertyValue = getCssPropertyValue(el, theme, property, breakpointName, debug);
const actualPropertyValue = getCssPropertyValue(el, theme, property, breakpointName, debug);
expect(actualPropertyValue).toBe(expectedPropertyValue);
}
export function expectMissingCssProperty(el, theme, property, breakpointName, debug) {
var actualPropertyValue = getCssPropertyValue(el, theme, property, breakpointName, debug);
const actualPropertyValue = getCssPropertyValue(el, theme, property, breakpointName, debug);
expect(actualPropertyValue).toBe(undefined);
}
var translateBreakpoints = function (theme) {
var breakpoints = theme.breakpoints;
var result = {};
Object.keys(breakpoints).forEach(function (key) {
const translateBreakpoints = (theme) => {
const breakpoints = theme.breakpoints;
const result = {};
Object.keys(breakpoints).forEach((key) => {
{

@@ -36,10 +36,10 @@ result[toMinMediaQuery(breakpoints[key])] = key;

};
export var getHtmlElementStyles = function (renderer, el, theme) {
export const getHtmlElementStyles = (renderer, el, theme) => {
if (!el) {
throw fail('The passed element must not be null');
}
var cssString = renderToString(renderer);
var classNames = el.getAttribute('class');
var cssObject = cssToObject(cssString, { camelCase: true });
var styles = {};
const cssString = renderToString(renderer);
const classNames = el.getAttribute('class');
const cssObject = cssToObject(cssString, { camelCase: true });
const styles = {};
cssObjectToIStyle(cssObject, classNames, styles, translateBreakpoints(theme));

@@ -46,0 +46,0 @@ return styles;

@@ -6,5 +6,5 @@ import { createFelaConfig } from '@indoqa/style-system';

import { RendererProvider, ThemeProvider } from 'react-fela';
var felaConfig = createFelaConfig();
export var renderer = createRenderer(felaConfig);
export var renderFelaComponent = function (wrappedComponent, theme) {
const felaConfig = createFelaConfig();
export const renderer = createRenderer(felaConfig);
export const renderFelaComponent = (wrappedComponent, theme) => {
return render(React.createElement(RendererProvider, { renderer: renderer },

@@ -11,0 +11,0 @@ React.createElement(ThemeProvider, { theme: theme }, wrappedComponent)));

@@ -5,4 +5,4 @@ import { ActionsObservable, StateObservable } from 'redux-observable';

import * as TypeMoq from 'typemoq';
export var createTestScheduler = function () {
return new TestScheduler(function (actual, expected) {
export const createTestScheduler = () => {
return new TestScheduler((actual, expected) => {
return expect(actual).toEqual(expected);

@@ -12,11 +12,10 @@ });

export function createTestAction$FromMarbles(testScheduler, marbles, values) {
var testObservable = testScheduler.createHotObservable(marbles, values);
const testObservable = testScheduler.createHotObservable(marbles, values);
return new ActionsObservable(testObservable);
}
export function testEpic(createEpic, inputActions, outputActions, inputMarble, outputMarble) {
var testScheduler = createTestScheduler();
testScheduler.run(function (_a) {
var expectObservable = _a.expectObservable;
var action$ = createTestAction$FromMarbles(testScheduler, inputMarble, inputActions);
var outputAction$ = createEpic(action$, testScheduler);
const testScheduler = createTestScheduler();
testScheduler.run(({ expectObservable }) => {
const action$ = createTestAction$FromMarbles(testScheduler, inputMarble, inputActions);
const outputAction$ = createEpic(action$, testScheduler);
expectObservable(outputAction$).toBe(outputMarble, outputActions);

@@ -26,6 +25,6 @@ });

export function testSimpleEpic(createEpic, inputAction, outputAction) {
var inputActions = {
const inputActions = {
a: inputAction,
};
var outputActions = {
const outputActions = {
a: outputAction,

@@ -36,14 +35,13 @@ };

export function mockAjax$(result, error) {
var ajaxResponseMock = TypeMoq.Mock.ofType();
ajaxResponseMock.setup(function (mock) { return mock.response; }).returns(function () { return result; });
var ajaxMock = TypeMoq.Mock.ofType();
const ajaxResponseMock = TypeMoq.Mock.ofType();
ajaxResponseMock.setup((mock) => mock.response).returns(() => result);
const ajaxMock = TypeMoq.Mock.ofType();
ajaxMock
.setup(function (mock) { return mock.post(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()); })
.returns(function () { return (error ? Rx.throwError(result) : Rx.of(ajaxResponseMock.target)); });
.setup((mock) => mock.post(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns(() => (error ? Rx.throwError(result) : Rx.of(ajaxResponseMock.target)));
return ajaxMock.target;
}
export function mockState(initialState) {
if (initialState === void 0) { initialState = {}; }
export function mockState(initialState = {}) {
return new StateObservable(new Rx.Subject(), initialState);
}
//# sourceMappingURL=testEpics.js.map
{
"name": "@indoqa/test-utils",
"version": "2.0.0-alpha.1",
"version": "2.0.0-alpha.2",
"author": "Indoqa Software Design und Beratung GmbH (https://www.indoqa.com)",

@@ -46,3 +46,3 @@ "description": "Test utilities for React, Fela and redux-observable.",

"devDependencies": {
"@indoqa/style-system": "^2.0.0-alpha.1",
"@indoqa/style-system": "^2.0.0-alpha.2",
"@testing-library/react": "^11.2.2",

@@ -58,3 +58,3 @@ "css": "^3.0.0",

},
"gitHead": "4efd903a821eda93f64c0390a61effe38d4f3a0a"
"gitHead": "2182989830011a11b431eb5d9a1bb828ceae3799"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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