Skip to content

Commit 3de587d

Browse files
committed
Add file extension test
1 parent cad2edd commit 3de587d

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

spec/js/convert-to-img-tag-spec.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,34 @@ describe('createMarkdownImages', function () {
121121
expect(result).toEqual(null)
122122
})
123123
})
124-
describe('when text contains only different extension', function () {
125-
beforeEach(function () {
126-
text = "hogehoge![title](https://user-images.githubusercontent.com/test.mp3)hogehoge"
127-
result = createMarkdownImages(text, "")
128-
})
129-
it('should return null ', function () {
130-
expect(result).toEqual(null)
124+
describe('when text contains supported extensions', function () {
125+
beforeEach(function () {
126+
text = "hogehoge![title](https://user-images.githubusercontent.com/test0.jpg)\n \
127+
hogehoge![title](https://user-images.githubusercontent.com/test1.png)\n \
128+
hogehoge![title](https://user-images.githubusercontent.com/test2.jpeg)\n \
129+
hogehoge![title](https://user-images.githubusercontent.com/test3.gif)"
130+
result = createMarkdownImages(text, "")
131+
})
132+
it('should match four md images', function () {
133+
let extensions = ["jpg", "png", "jpeg", "gif"]
134+
expect(result.length).toEqual(4)
135+
136+
result.forEach((markdownImage, index) => {
137+
expect(markdownImage.url).toEqual(`https://user-images.githubusercontent.com/test${index}.${extensions[index]}`)
138+
expect(markdownImage.imageTag).toEqual(`<img src=https://user-images.githubusercontent.com/test${index}.${extensions[index]} >`)
139+
expect(markdownImage.mdImageText).toEqual(`![title](https://user-images.githubusercontent.com/test${index}.${extensions[index]})`)
131140
})
132141
})
142+
})
143+
describe('when text contains only different extension', function () {
144+
beforeEach(function () {
145+
text = "hogehoge![title](https://user-images.githubusercontent.com/test.mp3)hogehoge"
146+
result = createMarkdownImages(text, "")
147+
})
148+
it('should return null ', function () {
149+
expect(result).toEqual(null)
150+
})
151+
})
133152
describe('when text contains md image', function () {
134153
describe('when text contains one md image', function () {
135154
beforeEach(function () {

src/js/convert-to-img-tag.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ function convertToImgTag(text, params) {
3030

3131
function createMarkdownImages(text, params) {
3232
let markdownImageArray = []
33-
const results = text.match(/\!\[.*\]\(https:\/\/\S+(jpg|jpeg|png|gif)\)/gmi)
34-
if (results == null) { return null}
33+
const results = text.match(/\!\[.*\]\(https:\S+(jpg|jpeg|png|gif)\)/gmi)
34+
if (results == null) { return null }
3535

3636
for (const mdImage of results) {
3737
const imageURL = mdImage.match(/https:\S+(jpg|jpeg|png|gif)/i)[0]

0 commit comments

Comments
 (0)