New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

rax-image

Package Overview
Dependencies
Maintainers
8
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rax-image - npm Package Compare versions

Comparing version 2.2.0 to 2.2.1-beta.0

2

lib/index.js

@@ -54,3 +54,3 @@ "use strict";

nativeProps.onLoad = (0, _rax.useCallback)(function (e) {
if (e.success !== null) {
if (e.success !== null && e.success !== undefined) {
if (e.success) {

@@ -57,0 +57,0 @@ onLoad && onLoad(e);

{
"name": "rax-image",
"version": "2.2.0",
"version": "2.2.1-beta.0",
"description": "Image component for Rax.",

@@ -5,0 +5,0 @@ "license": "BSD-3-Clause",

@@ -1,2 +0,2 @@

import {createElement, Component} from 'rax';
import {createElement, Component, render} from 'rax';
import renderer from 'rax-test-renderer';

@@ -6,3 +6,18 @@ import Image from '../../lib/';

describe('Image', () => {
it('should render null when no source or source.uri', () => {
beforeEach(function() {
jest.useFakeTimers();
});
function createNodeElement(tagName) {
return {
nodeType: 1,
tagName: tagName.toUpperCase(),
attributes: {},
style: {},
childNodes: [],
parentNode: null
};
}
it('should render empty img tag when no source or source.uri', () => {
const component = renderer.create(

@@ -12,3 +27,4 @@ <Image />

let tree = component.toJSON();
expect(tree).toEqual(null);
expect(tree.tagName).toEqual('IMG');
expect(tree.attributes).toEqual(undefined);
});

@@ -40,2 +56,111 @@

});
it('should call onLoad when callback with success:true', () => {
let container = createNodeElement('div');
let isLoad = false;
const onLoad = () => {
isLoad = true;
};
render(<Image source={{uri: 'a.png'}} style={{
width: '20rem',
height: '20rem'
}} onLoad={onLoad} />, container);
expect(container.childNodes[0].tagName).toEqual('IMG');
container.childNodes[0].eventListeners.load({
success: true
});
expect(isLoad).toEqual(true);
});
it('should call onError when callback with success:false', () => {
let container = createNodeElement('div');
let isError = false;
const onError = () => {
isError = true;
};
render(<Image source={{uri: 'a.png'}} style={{
width: '20rem',
height: '20rem'
}} onError={onError} />, container);
expect(container.childNodes[0].tagName).toEqual('IMG');
container.childNodes[0].eventListeners.load({
success: false
});
expect(isError).toEqual(true);
});
it('should call onLoad when callback with currentTarget info', () => {
let container = createNodeElement('div');
let isLoad = false;
const onLoad = () => {
isLoad = true;
};
render(<Image source={{uri: 'a.png'}} style={{
width: '20rem',
height: '20rem'
}} onLoad={onLoad} />, container);
expect(container.childNodes[0].tagName).toEqual('IMG');
container.childNodes[0].eventListeners.load({
currentTarget: {
naturalWidth: 20,
naturalHeight: 20
}
});
expect(isLoad).toEqual(true);
});
it('should call onError when callback with error currentTarget info', () => {
let container = createNodeElement('div');
let isError = false;
const onError = () => {
isError = true;
};
render(<Image source={{uri: 'a.png'}} style={{
width: '20rem',
height: '20rem'
}} onError={onError} />, container);
expect(container.childNodes[0].tagName).toEqual('IMG');
container.childNodes[0].eventListeners.load({
currentTarget: {
naturalWidth: 0,
naturalHeight: 0
}
});
expect(isError).toEqual(true);
});
it('should call onError when image load error', () => {
let container = createNodeElement('div');
let isError = false;
const onError = () => {
isError = true;
};
render(<Image source={{uri: 'a.png'}} style={{
width: '20rem',
height: '20rem'
}} onError={onError} />, container);
expect(container.childNodes[0].tagName).toEqual('IMG');
container.childNodes[0].eventListeners.error();
expect(isError).toEqual(true);
});
});

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