Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test(isDataUrl, () => {
//valid input
given('data:image/svg+xml;base64,PHN2ZyB4bWxu').expect(true)
// invalid inputs
forCases([given('data:foobar'), given('foobar')]).expect(false)
// attempted XSS attack
given(
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+P+/HgAFhAJ/wlseKgAAAABJRU5ErkJggg=="/>'
).expect(false)
})
test(coalesce, function() {
given().expect(undefined)
given(null, []).expect([])
given(null, [], {}).expect([])
given(null, undefined, 0, {}).expect(0)
const a = null,
c = 0,
d = 1
let b
given(a, b, c, d).expect(0)
})
})
test(coalesce, function() {
given().expect(undefined)
given(null, []).expect([])
given(null, [], {}).expect([])
given(null, undefined, 0, {}).expect(0)
const a = null,
c = 0,
d = 1
let b
given(a, b, c, d).expect(0)
})
})
test(formatRelativeDate, () => {
given(new Date(2018, 9, 31).getTime() / 1000)
.describe('when given the end of october')
.expect('in 2 days')
})
test(formatDate, () => {
given(new Date(2017, 0, 1).getTime())
.describe('when given the beginning of this year')
.expect('january')
})
})
test(age, () => {
given(Date.now())
.describe('when given the current timestamp')
.expect('brightgreen')
given(new Date())
.describe('when given the current Date')
.expect('brightgreen')
given(new Date(2001, 1, 1))
.describe('when given a Date many years ago')
.expect('red')
given(monthsAgo(2))
.describe('when given a Date two months ago')
.expect('yellowgreen')
given(monthsAgo(15))
.describe('when given a Date 15 months ago')
.expect('orange')
})
test(makeLogo, () => {
forCases([
given('npm', { logo: 'image/svg+xml;base64,PHN2ZyB4bWxu' }),
given('npm', { logo: 'data:image/svg+xml;base64,PHN2ZyB4bWxu' }),
given('npm', { logo: 'data:image/svg xml;base64,PHN2ZyB4bWxu' }),
given('npm', { logo: 'data:image/svg+xml;base64,PHN2ZyB\n4bWxu' }),
]).expect('data:image/svg+xml;base64,PHN2ZyB4bWxu')
forCases([given('npm', { logo: '' }), given(undefined, {})]).expect(
undefined
)
given('npm', {}).expect(
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MCA0MCI+PHBhdGggZD0iTTAgMGg0MHY0MEgwVjB6IiBmaWxsPSIjY2IwMDAwIi8+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTcgN2gyNnYyNmgtN1YxNGgtNnYxOUg3eiIvPjwvc3ZnPgo='
)
})
})
test(isHexColor, () => {
forCases([given('f00bae'), given('4c1'), given('ABC123')]).expect(true)
forCases([
given('f00bar'),
given(''),
given(undefined),
given(null),
given(true),
given([]),
given({}),
given(() => {}),
]).expect(false)
})
test(testColor, () => {
forCases([
given('#4c1', 'color'),
given('#4c1', 'colorB'),
given('#4c1', 'colorscheme'),
]).expect('#4c1')
})
})
test(testColor, () => {
forCases([
given('#4c1', 'color'),
given('#4c1', 'colorB'),
given('#4c1', 'colorscheme'),
]).expect('#4c1')
})
})